Uncaught TypeError: Cannot read property ‘linear’ of undefined
In D3 v4 it is no longer named d3.scale.linear(). Use d3.scaleLinear() instead.
In D3 v4 it is no longer named d3.scale.linear(). Use d3.scaleLinear() instead.
Instead of d3.scale.category10() use d3.scaleOrdinal(d3.schemeCategory10); Create a color scale like this: var color = d3.scaleOrdinal(d3.schemeCategory10); use the color like this in the code same as in V3: svg.append(“rect”) .attr(“x”, 10) .attr(“y”, 10) .attr(“width”, 100) .attr(“height”, 100) .style(“fill”, color(3)) read here Reference here working code here
Your answer will work, but for posterity, these methods are more generic. Remove all children from HTML: d3.select(“div.parent”).html(“”); Remove all children from SVG/HTML: d3.select(“g.parent”).selectAll(“*”).remove(); The .html(“”) call works with my SVG, but it might be a side effect of using innerSVG.
If you care about file size or topology, then use TopoJSON. If you don’t care about either, then use GeoJSON for simplicity’s sake. The primary advantage of TopoJSON is size. By eliminating redundancy and using a more efficent fixed-precision integer encoding of coordinates, TopoJSON files are often an order of magnitude smaller than GeoJSON files. … Read more
My answer is close to Jan van der Laan’s, but you can simplify things slightly because you don’t need to compute the geographic centroid; you only need the bounding box. And, by using an unscaled, untranslated unit projection, you can simplify the math. The important part of the code is this: // Create a unit … Read more