Public
Edited
Nov 11, 2022
1 fork
Insert cell
superstore_dataset2011-2015.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
data = superstore_dataset20112015
Insert cell
Insert cell
Insert cell
sankey = {
const sankey = d3.sankey()
.nodeId(d => d.name)
.nodeAlign(d3[`sankey${align[0].toUpperCase()}${align.slice(1)}`])
.nodeWidth(15)
.nodePadding(10)
.extent([[1, 5], [width - 1, height - 5]]);
return ({nodes, links}) => sankey({
nodes: nodes.map(d => Object.assign({}, d)),
links: links.map(d => Object.assign({}, d))
});
}
Insert cell
Insert cell
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;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more