If you have a CSV file, the data generally needs to be structured into an array of nodes and edges. Here’s a basic example of how to map a CSV structure to match the ApexSankey format:
- Nodes: Extract unique values from the “Source” and “Target” columns to create the nodes.
id is for uniquely identifying nodes and title is for showing node labels. title will be also used for showing tooltips for node-to-node connections.
const nodes = [
{ id: "A", title: "A" },
{ id: "B", title: "B" },
{ id: "C", title: "C" },
{ id: "D", title: "D" }
];
- Edges: Use the “Source”, “Target”, and “Value” columns to define the edges.
const edges = [
{ source: "A", target: "B", value: 10 },
{ source: "A", target: "C", value: 20 },
{ source: "B", target: "D", value: 15 },
{ source: "C", target: "D", value: 25 }
];
- Combined Data Structure:
const sankeyOptions = {
nodes: [
{ id: "A", title: "A" },
{ id: "B", title: "B" },
{ id: "C", title: "C" },
{ id: "D", title: "D" }
],
edges: [
{ source: "A", target: "B", value: 10 },
{ source: "A", target: "C", value: 20 },
{ source: "B", target: "D", value: 15 },
{ source: "C", target: "D", value: 25 }
]
}
Please wait...