React Sankey - Customize Labels
NOTE
You can use the customizeText function to change the labels' text. Its argument contains a Node object that provides information about the node being customized. The function should return a string value that will be used as a label's text.
In the following example, the customizeText function is used to add incoming and outgoing weight values to the label:
App.tsx
- import React from 'react';
- import Sankey, { Label } from 'devextreme-react/sankey';
- import type { dxSankeyNode } from 'devextreme/viz/sankey';
- const weightsReducer = (accumulator: number, currentValue: { weight: number }) => {
- return accumulator + currentValue.weight;
- };
- const customizeText = (node: dxSankeyNode) => {
- return `${node.label} (in: ${(node.linksIn ?? []).reduce(weightsReducer, 0)}, out: ${(node.linksOut ?? []).reduce(weightsReducer, 0)})`;
- };
- function App() {
- return (
- <Sankey ... >
- <Label customizeText={customizeText} />
- </Sankey>
- );
- }
- export default App;