Data Binding
You can bind the Sankey Chart to data by using the component's data
property. This property requires your data to match the SankeyData
format. However, if your data has a different format, you must process and structure it before feeding it to the component.
Binding to SankeyData
The following example demonstrates how to set the data
property to data with the SankeyData
format. The data is located in the data.ts
file.
Binding to Flat Data
When the data is present as an array of objects, it needs to be transformed to the SankeyData
format.
This is achieved in the below example using the createSankeyData
method. It takes an array of data, dimensions
, and measure
as input parameters and returns an object that conforms to the SankeyData
interface. The dimensions
refer to the Sankey nodes
while the measure
refers to the value that will be used to set the value of the links
.
Customize Nodes from Flat Data
To customize the element instances when the data is an array of objects, transform the data
that stores the returned value of the createSankeyData
method.
The following example demonstrates this approach by mapping the data.nodes
to set the color to lightblue
for the nodes with an even id, and lightgreen
for the nodes with an odd id.