3๐
โ
You should register the chart from chart.js
See an example here
import {
Chart as ChartJS,
CategoryScale,
LinearScale,
PointElement,
LineElement,
Title,
Tooltip,
Legend,
} from 'chart.js';
ChartJS.register(CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip, Legend);
0๐
You can try to add this line in the beginning of your file, it seems to fix this issue:
import Chart from "chart.js/auto";
0๐
You could create the chart in the render()
method.
render() {
return (
<Line
data={this.state.data}
options={this.state.options}
/>
);
}
Please take a look at the following StackBlitz and see how it works with your amended code.
Source:stackexchange.com