Sankey_data = {
var graph = new Object({
nodes: new Array(),
links: new Array(),
units: "ton"
});
var nodes = new Array();
var links = new Array();
for(let i of data){
if(nodes.indexOf(i["Segment"])==-1){
nodes.push(i["Segment"]);
}
if(nodes.indexOf(i["Category"])==-1){
nodes.push(i["Category"]);
}
var nowindex = links.indexOf(i["Category"]+i["Segment"]);
if(nowindex==-1){
links.push(i["Category"]+i["Segment"]);
graph.links.push(new Object({
source: i["Category"],
target: i["Segment"],
value: 1
}));
} else {
graph.links[nowindex].value = graph.links[nowindex].value + 1;
}
}
for(let i of nodes){
graph.nodes.push(new Object({name: i, category: i}));
}
return graph;
}