Skip to content

Integration

chartjs-chart-treemap can be integrated with plain JavaScript or with different module loaders. The examples below show to load the plugin in different systems.

  • Chart.js 4.0 or newer. Registering the controller against an older Chart.js throws with a message naming the required version, rather than failing later with an unrelated error.
  • ESM or UMD; both builds ship in the package.

Chart.js 3 users stay on chartjs-chart-treemap@4. Chart.js 3 exposes chart.js/helpers through an exports map that Webpack 5 does not accept, which is why bundling this package with Chart.js 3 could fail to resolve that subpath. Upgrading Chart.js is the fix; the combination is verified by a Webpack build in this repository’s test suite.

<script src="path/to/chartjs/dist/chart.min.js"></script>
<script src="path/to/chartjs-chart-treemap/dist/chartjs-chart-treemap.min.js"></script>
<script>
let myChart = new Chart(ctx, {type: 'treemap', ...});
</script>
import {Chart, registerables} from 'chart.js';
import {TreemapController, TreemapElement} from 'chartjs-chart-treemap';
Chart.register(...registerables, TreemapController, TreemapElement);