react-chartjs-2 icon indicating copy to clipboard operation
react-chartjs-2 copied to clipboard

Use chartjs-plugin-trendline

Open XopherDesign opened this issue 7 years ago • 3 comments

I can't seem to figure out how to use chartjs-plugin-trendline with this project, any tips? What I've done so far is npm i chartjs-plugin-trendline import 'chartjs-plugin-trendline'; then added the trendlineLinear: { style: "rgba(255,105,180, .8)", lineStyle: "solid", width: 2 } to the dataset, but no line appears Thanks!

XopherDesign avatar Sep 06 '19 19:09 XopherDesign

It started working after a bit, must of been a caching issue

XopherDesign avatar Sep 06 '19 20:09 XopherDesign

@XopherDesign Can you share the code that worked? I am having a similar issue. I even tried to clear cache using Ctrl+Shift+R, but it didn't work. Is the plugin supposed to be just imported, or registered globally via componentDidMount or just passed as plugins prop?

3atharvkurdukar avatar Jun 04 '21 09:06 3atharvkurdukar

This works for me:

// "react-chartjs-2": "^3.1.1",
import {Chart, Bar} from 'react-chartjs-2';

Chart.register(chartTrendline);

function MyBarChart() {
  const chartData = {
    ...
    datasets: [
      {
        ...,
        trendlineLinear: {...},
      },
    ],
  };
  const chartOptions = {...};
  return <Bar data={chartData} options={chartOptions} />;
}

owenchu avatar Dec 04 '21 00:12 owenchu