Reputation: 107
I would like to add a treemap chart from chartjs-chart-treemap into my existing project that uses react-chartjs-2.
I tried so far:
import ChartComponent from 'react-chartjs-2';
export default class TreeMap extends React.Component {
render() {
return (
<ChartComponent
{...this.props}
ref={ref => this.chartInstance = ref && ref.chartInstance}
type='treemap'
/>
);
}
}
,but I can see following error when trying to render this component:
Error: "treemap" is not a chart type.
How can I use chartjs-chart-treemap with React?
Upvotes: 3
Views: 1880
Reputation: 155
the chartjs-chart-treemap library has to be imported to the component file
import ChartComponent from 'react-chartjs-2';
import 'chartjs-chart-treemap';
export default class TreeMap extends React.Component {
render() {
return (
<ChartComponent
{...this.props}
ref={ref => this.chartInstance = ref && ref.chartInstance}
type='treemap'
/>
);
}
}
Upvotes: 3