Anyone can tell me why I can not read this json and display it on sankey
I have to use d3.js if you put less data it works json's list link
Anyone can tell me why I can not read this json and display it on sankey
I have to use d3.js if you put less data it works json's list link
The D3's Sankey plugin uses the numeric (index) position of the element in the nodes
array for the source
and target
properties of the links
array. In your example you are using names. You can preprocess the file before use to make the replacement, or make the replacement 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 link that cites some alternatives to address this issue.