[Chartjs]-React chart js, title is not displayed

8👍

This is because you are using treeshaking and not importing and registering the Title

To fix it either import and registr every component you are using, list of all components can be found here like so:

import {Chart, Title} from 'chart.js';
Chart.register(Title);

Or use the auto import to let chart.js register everything for you:

import 'chart.js/auto'

0👍

Use this:

a) Ensure you have installed chart.js:

npm install chart.js

b) Import Chart and Title as shown below:

import { Chart, Title } from "chart.js";

c) Register Title as show below:

Chart.register(Title);

d) Then set the title as given below:

options: {
  responsive: true,
  plugins: {
     title: {
        display: true,
        text: 'Bar Chart'
      }
   }
}

Leave a comment