Charts in React

 


install the command for charts

==========================================================

npm i react-chartjs-2 chart.js



imports for the file

==========================================================

import Line, { Bar, Doughnut, Pie } from "react-chartjs-2";



js file

==========================================================


const data = {

    labels: ["mon", "tue", "wed", "thu", "fri", "sat"],

    datasets: [

      {

        label: "sales for the week",

        data: ["9", "8", "7", "4", "5", "6", "3"],

        backgroundColor: [

          "red",

          "blue",

          "orange",

          "black",

          "grey",

          "green",

          "white",

        ],

      },

    ],

  };



html

==========================================================


 <Bar data={data} />

      <Doughnut data={data} />

      <Pie data={data} />

Comments