Change the ticks on x-axis

The default ticks for quantitative scales are multiples of 2, 5 and 10. You appear to want multiples of 6; though unusual, this could make sense depending on the nature of the underlying data. So, while you can use axis.ticks to increase or decrease the tick count, it will always return multiples of 2, 5 … Read more

How/Where do I get geoJSON data for states, provinces, and administrative regions of non-US countries? [closed]

This process is now simplified (July 2014) compared to the steps I see in the accepted answer. It now seems much easier to get this data. I at first floundered around the web hoping I could just download a bunch of standard maps in GeoJSON format, but came up empty other than standard US/Canada offerings. … Read more

D3: How to refresh a chart with new data?

Create one function that (re)draws the pie when it’s created and when it’s updated. New data should be added to pie using enter() and old data should be removed using exit().remove() It is as simple as this: path.enter().append(“path”) .attr(“fill”, function(d, i) { return color(i); }) .attr(“d”, arc) .each(function(d) {this._current = d;} ); path.transition() .attrTween(“d”, arcTween); … Read more

Calculate width of text before drawing the text

I know you asked about D3, but this might be a native solution to your issue. The HTML5 canvas 2D context has some built-in functionality to measure text. You might be able to tap into that to measure text for other APIs like SVG. If it’s not 100% accurate, surely it’s proportional to the correct … Read more

D3 force directed layout with bounding box

There’s a bounding box example in my talk on force layouts. The position Verlet integration allows you to define geometric constraints (such as bounding boxes and collision detection) inside the “tick” event listener; simply move the nodes to comply with the constraint and the simulation will adapt accordingly. That said, gravity is definitely a more … Read more

Difference between svg and canvas in d3.js

The differences listed in the linked question/answers speak to the general differences between svg and canvas (vector/raster, etc). However, with d3 these differences have additional implications, especially considering that a core part of d3 is data binding. Data Binding Perhaps the most central feature of d3 is data binding. Mike Bostock states he needed to … Read more

Styles in component for D3.js do not show in angular 2

Update Angular and SASS agreed on supporting ::ng-deep (instead of >>> or /deep/) a while ago until ::slotted or whatever makes it into browser standards becomes available in all browsers. ViewEncapsulation.Emulated (default) That’s by design. Angular adds class names unique to components and rewrites the added styles to only apply to the components where they … Read more

Hyperlinks in d3.js objects

It is quite easy, just add some more “key” : “value” pairs. Example: “children”: [ { “name”: “Google”, “size”: 3938, “url”: “https://www.google.com” }, { “name”: “Bing”, “size”: 3938, “url”: “http://www.bing.com” } ] Of course, in your d3 code you then need to append <svg:a> tags and set their xlink:href attribute. Here is some html and … Read more

Can enter() selection be reused after append/insert?

No. The purpose of the data-join is to synchronize elements with data, creating, removing or updating elements as necessary. If you create elements twice, the elements will no longer correspond one-to-one with the bound array of data. If you want two elements to correspond to each datum, then append a group (G) element first to … Read more