Sankey D3.js problem diagram with large data

Asked

Viewed 46 times

1

someone can tell me why I can’t read this json and show on Sankey

I have to use D3.js if you put in less data it works json list http://pastebin.com/p3mzVb2m

1 answer

1

The D3 Sankey plugin uses position numeric (index) of the element in the array nodes for property source and target array links. In your example you are using names. You can pre-process the file before use to overwrite, or do the overwriting in real time using:

d3.json("sankey-data.json", function(error, data) {
   if(error) console.log(error)

   function getIndex(name) { // descobre o índice do nome
       return data.nodes.findIndex(function(d) {
           return d.name == name;
       });
   }

   for(var i = 0; i < data.links.length; i++) { // troca nomes por índices
       data.links[i].target = getIndex(data.links[i].target);
       data.links[i].source = getIndex(data.links[i].source);
   }

   // agora o array *data* pode ser usado pelo sankey

...

A second problem you may encounter is an infinite loop, as it seems to me that your data contains circular paths, which is not supported by Sankey. Test your file with less data (removing circular paths) and then take a look at https://github.com/d3/d3-plugins/pull/39 that cites some alternatives to dealing with this issue.

  • hello I’ve got it. what I did was put in the source data a name before type source+ field value and so already generates the chart with equal names it happens a bit

  • converted the data to csv. no longer using json. seems slower to me.

  • I saw why I couldn’t do it, I have to generate two types of nodes for the two columns for example , name : "a " and name: "a" and then do the same in query origin destination .... give a spacing and already work...

  • it is possible to do a new data filtering or without doing a new query the bd shows only those that go from source!= target

Browser other questions tagged

You are not signed in. Login or sign up in order to post.