javascriptreactjschartschartist.js

Add legend to Chart in react-chartist


I installed plugin chartist-plugin-legend. I want to add legend to my chart, but get the error 'Chartist' is not defined no-undef. How i can add the legend to chart?

import ChartistGraph from 'react-chartist';
import ChartistTooltip from 'chartist-plugin-tooltips-updated';

const options = {
 
  plugins: [
    Chartist.plugins.legend(),
    ChartistTooltip({
      anchorToPoint: false,
      appendToBody: true,
      seriesName: false,
    }),
  ],
};

<ChartistGraph
          className='ct-chart-line'
          data={data}
          options={options}
          type='Line'
/>


Solution

  • It doesn't look like you have imported the Chartist library. You would need to add this to your project with npm install --save chartist and import Chartist from 'chartist';.