Integration
import { Chart, LinearScale } from 'chart.js'import { Flow, NodeElement, SankeyController } from 'chartjs-chart-sankey'
Chart.register(LinearScale, SankeyController, Flow, NodeElement)NodeElement is the element of a node. The controller does not look it up, so a chart also works when only the controller and Flow are registered.
CommonJS
Section titled “CommonJS”The CommonJS entry registers the sankey controller, the flow element and the node element as side effects.
const { Chart, LinearScale } = require('chart.js')require('chartjs-chart-sankey')
Chart.register(LinearScale)Browser Bundle
Section titled “Browser Bundle”For script tag usage, load the browser bundle after Chart.js. The browser bundle registers the sankey controller, the flow element and the node element automatically.
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script><script src="https://cdn.jsdelivr.net/npm/chartjs-chart-sankey"></script>The same bundle can be loaded from UNPKG.
<script src="https://unpkg.com/chart.js"></script><script src="https://unpkg.com/chartjs-chart-sankey"></script>If a CDN does not use the package metadata for its default file, reference the browser bundle directly.
<script src="https://cdn.jsdelivr.net/npm/chartjs-chart-sankey/dist/chartjs-chart-sankey.min.js"></script>The built ESM bundle exports the controller and the elements and requires explicit registration.
import { Flow, NodeElement, SankeyController } from 'chartjs-chart-sankey/dist/chartjs-chart-sankey.esm.js'
Chart.register(SankeyController, Flow, NodeElement)