How to use this plugin with react-chartjs-2 (chartjs 3 version) #46
Replies: 3 comments
-
Use canvas, ref for it and useEffect: <canvas ref={canvas}></canvas>
useEffect(() => {
const ctx = canvas && canvas.current && canvas.current.getContext('2d')
const chart = new Chart(ctx, options)
} |
Beta Was this translation helpful? Give feedback.
-
I haven't used import {Chart} from 'chart.js';
import { Component } from 'react'
import ChartComponent from 'react-chartjs-2';
import {TreemapController, TreemapElement} from 'chartjs-chart-treemap';
// Need to register
Chart.register(TreemapController, TreemapElement);
export default class TreeMap extends Component {
render() {
return (
<ChartComponent
{...this.props}
ref={ref => this.chartInstance = ref && ref.chartInstance}
type='treemap'
/>
);
}
} |
Beta Was this translation helpful? Give feedback.
-
The following code gives a design-time error of import { Chart as ChartJS } from "chart.js";
import ChartComponent from "react-chartjs-2";
import React, { useRef } from "react";
import { TreemapController, TreemapElement } from "chartjs-chart-treemap";
ChartJS.register(TreemapController, TreemapElement);
export default function TreeMapChart(props: React.JSX.IntrinsicAttributes) {
const chartInstanceRef = useRef(null);
return (
<ChartComponent
{...props}
// eslint-disable-next-line no-return-assign
ref={(ref: { chartInstance: any }) => (chartInstanceRef.current = ref && ref.chartInstance)}
type="treemap"
/>
);
} How to fix this so that I can use |
Beta Was this translation helpful? Give feedback.
-
I am trying to use chartjs tree map plugin with react-chartjs-2 library (chartjs 3 version), the below is the pervious version usage of treemap
How to implement it in new version
Beta Was this translation helpful? Give feedback.
All reactions