Cannot use attr with an object in D3 v4

From D3 v4 onwards you cannot use objects to set attr or style anymore. To do so, you have to reference the mini library D3-selection-multi: <script src=”https://d3js.org/d3-selection-multi.v0.4.min.js”></script> After doing that, change your code from attr to attrs (yes, like a plural): var textLabels = labelGroups.append(“text”).attrs({ //mind the ‘s’ here————————-ˆ }); Do the same for the … Read more

What’s the best way to make a d3.js visualisation layout responsive?

There’s another way to do this that doesn’t require redrawing the graph, and it involves modifying the viewBox and preserveAspectRatio attributes on the <svg> element: <svg id=”chart” viewBox=”0 0 960 500″ preserveAspectRatio=”xMidYMid meet”> </svg> Update 11/24/15: most modern browsers can infer the aspect ratio of SVG elements from the viewBox, so you may not need … Read more

Show data on mouseover of circle

I assume that what you want is a tooltip. The easiest way to do this is to append an svg:title element to each circle, as the browser will take care of showing the tooltip and you don’t need the mousehandler. The code would be something like vis.selectAll(“circle”) .data(datafiltered).enter().append(“svg:circle”) … .append(“svg:title”) .text(function(d) { return d.x; }); … Read more