[Chartjs]-Chart.register is not a function

3๐Ÿ‘

You need to import Chart from chart.js and not from Reacht-chartjs-2 to register it like so:

import {Chart} from 'chart.js';
import {Chart as ReactChart} from 'react-chartjs-2';
import StreamingPlugin from 'chartjs-plugin-streaming';

Chart.register(StreamingPlugin);

0๐Ÿ‘

Hi I found the answer because i had the same problem.

remove Chart from import react-chartjs-2
and import Chart from chart.js/auto so your imports would look like this.

import { Line } from "react-chartjs-2";
import "chartjs-adapter-luxon";
import StreamingPlugin from "chartjs-plugin-streaming";
import "./App.css";
import Chart from "chart.js/auto";

Chart.register(StreamingPlugin);```

Hope this helped.

-1๐Ÿ‘

What worked for me was using chart.js@3.8.0, chartjs-chart-geo@3.7.2, and react-chartjs-2@4.1.0. Like in this codepen.

Leave a comment