d3.js

Properly display bin width in barChart using dc.js and crossfilter.js

拥有回忆 提交于 2019-12-30 00:51:07
问题 I'm making a bar chart using the Dimensional Charting javascript library dc.js, which is based on d3 and crossfilter. All I want to do is display a histogram with a specified number of bins, this should be easy using the barChart function. I have an array called data which contains floating-point values between 0 and 90000, and I just want to display the distribution using a histogram with 10 bins. I use the following code to produce the histogram below: var cf = crossfilter(data); var dim =

D3js: how to generate standalone SVG files? (Nodejs)

青春壹個敷衍的年華 提交于 2019-12-29 14:23:45
问题 Given a D3js code , such as: var square= function() { var svg = window.d3.select("body") .append("svg") .attr("width", 100) .attr("height", 100); svg.append("rect") .attr("x", 10) .attr("y", 10) .attr("width", 80) .attr("height", 80) .style("fill", "orange"); } square(); svg { border: 1px solid grey;} /* just to visualized the svg file's area */ <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js"></script> <body></body> How to generate a correct stand alone *.svg file with

How do I rotate or scale (transform) an SVG path relative to its center point?

五迷三道 提交于 2019-12-29 08:50:50
问题 I'm trying to rotate and scale shapes within an SVG around their center point. I've looked into several libraries, including Jquery, Greensock, D3, RaphaelJS, but I haven't been able to find any that provide a straightforward way to accomplish this. Each animates the shape from the origin point (which I understand is the default). I want to be able to spin a shape around its center point or scale it up or down from the center point. Here are a couple examples using Greensock and D3 that

d3 version 4 workaround for drag origin

空扰寡人 提交于 2019-12-29 08:48:08
问题 In v3 I used drag origin to prevent a noticeable jump due to the mouse-position/element-coordinates offset. Is there an alternative in v4 as the origin function has been removed? var drag1 = d3.behavior.drag() .origin(function () { var t = d3.select(this); return { x: t.attr("x") + d3.transform(t.attr("transform")).translate[0], y: t.attr("y") + d3.transform(t.attr("transform")).translate[1] }; }) .on("drag", function (d, i) { d3.select(this).attr("transform", function (d, i) { return

D3 v4 - Accessing selection array and find corresponding element

三世轮回 提交于 2019-12-29 08:41:37
问题 I'm trying to get a constraint relaxing to work for my piechart. It is based on this example https://jsfiddle.net/thudfactor/HdwTH/ but the relaxing method used seems not to work with v4 any more. The concrete problem is how they access the selection group array directly: textLabels = labelGroups.append("text").attr( ... ); if(again) { labelElements = textLabels[0]; <------------- here textLines.attr("y2",function(d,i) { labelForLine = d3.select(labelElements[i]); return labelForLine.attr("y"

D3: Select and alter external SVG?

一笑奈何 提交于 2019-12-29 07:51:33
问题 Is it possible to select and alter elements in an embedded (external) SVG , created in Adobe Illustrator? html: <object data="circles.svg" type="image/svg+xml" id="circles"></object> circles.svg: <svg xmlns="http://www.w3.org/2000/svg" width="100px" height="100px" > <circle id="c_red" fill="#A00" stroke="#000" cx="40" cy="40" r="40"/> <circle id="c_grn" fill="#0A0" stroke="#000" cx="60" cy="60" r="40"/> </svg> d3 code: <script> var my_circles = d3.select("#circles svg").selectAll("circles");

Avoid data caching when using d3.text

浪尽此生 提交于 2019-12-29 07:46:29
问题 I am using d3.text() to load a text file. I want to avoid using the cache of the browser. Anybody knows how this can be done? Thanks! 回答1: Don't see how the MIME type would do anything for this issue. You can avoid caching by appending a random number to the url (this is a general practice that has nothing to do with d3). So, if your url is var url = 'http://www.example.com/somthing'; Then make your request d3.text( url + '?' + Math.floor(Math.random() * 1000) ); More info here 来源: https:/

d3.svg.line() error: Uncaught TypeError: Cannot read property 'line' of undefined

て烟熏妆下的殇ゞ 提交于 2019-12-29 07:22:07
问题 I am using the following code to try to draw a path using d3.js I have tried various code examples on the web about the same and have been getting the same error everywhere. Following is the JS: <script type="text/javascript"> var svg; //The data for our line lineData = [ { "x": 1, "y": 5}, { "x": 20, "y": 20}, { "x": 40, "y": 10}, { "x": 60, "y": 40}, { "x": 80, "y": 5}, { "x": 100, "y": 60}]; //This is the accessor function we talked about above var lineFunction = d3.svg.line() .x(function

d3.js scatter plot - zoom/drag boundaries, zoom buttons, reset zoom, calculate median

半世苍凉 提交于 2019-12-29 06:58:07
问题 I've built a d3.js scatter plot with zoom/pan functionality. You can see the full thing here (click 'Open in a new window' to see the whole thing): http://bl.ocks.org/129f64bfa2b0d48d27c9 There are a couple of features that I've been unable to figure out, that I'd love a hand with it if someone can point me in the right direction: I want to apply X/Y zoom/pan boundaries to the area, so that you can't drag it below a certain point (e.g. zero). I've also made a stab at creating Google Maps

How to read in CSV with d3 v4?

徘徊边缘 提交于 2019-12-29 05:22:19
问题 I'm just having a little trouble understanding the documentation for CSV Parse with D3. I currently have: d3.parse("data.csv",function(data){ salesData = data; }); But I keep on getting the error: Uncaught TypeError: d3.parse is not a function What is this supposed to look like? I'm just a little confused, and the only examples that I could find was something like this. I also tried something like: d3.dsv.parse("data.csv",function(data){ salesData = data; }); and got: Uncaught TypeError: