D3: update data with multiple elements in a group

The key is to handle all the selections, not just the enter selection: var myGroups = svg.selectAll(‘g’).data(myData); // enter selection var myGroupsEnter = myGroups.enter().append(“g”); myGroupsEnter.append(“line”); myGroupsEnter.append(“polygon”); // … // update selection — this will also contain the newly appended elements myGroups.select(“line”).attr(…); // … // exit selection myGroups.exit().remove(); There are two things here that warrant further … Read more

Drawing Multiple Lines in D3.js

Yes. First I would restructure your data for easier iteration, like this: var series = [ [{time: 1, value: 2}, {time: 2, value: 4}, {time: 3, value: 8}], [{time: 1, value: 5}, {time: 2, value: 9}, {time: 3, value: 12}], [{time: 1, value: 3}, {time: 2, value: 2}, {time: 3, value: 2}], [{time: 1, value: … Read more

Loading D3.js data from a simple JSON string

for remote data.json replace : d3.tsv(“data.tsv”, function(error, data) {…} with : d3.json(“data.json”, function(error, data) { console.log(data); // this is your data }); for local data: var myData = { {date:’2013-05-01′, frequency:99}, {date:’2013-05-02′, frequency:24} }; function draw(data) { console.log(data); // this is your data } draw(myData);

d3 importing csv file to array [duplicate]

In d3 v5 the API for fetching data has changed quite a bit, which became necessary as the underlying workings have switched from using XMLHttpRequest to the Fetch API. In prior versions of D3 up to v4 your code would have behaved as you expected printing the single resulting array. The new API for d3.csv(), … 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

Loading external csv file in jsfiddle

The approach I usually use for CSV data in JSFiddle examples is a. Put the data in a <pre> block at the end of the HTML mark-up, usually with the id “data”. b. Add pre {display:none;} to the CSS. c. Replace the d3.csv(filename, callback) function call with a d3.csv.parse(text) call, using the text content of … 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

Center a map in d3 given a geoJSON object

With d3 v4 or v5 its getting way easier! var projection = d3.geoMercator().fitSize([width, height], geojson); var path = d3.geoPath().projection(projection); and finally g.selectAll(‘path’) .data(geojson.features) .enter() .append(‘path’) .attr(‘d’, path) .style(“fill”, “red”) .style(“stroke-width”, “1”) .style(“stroke”, “black”); Enjoy, Cheers

tech