Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react chart js 2

npm install --save react-chartjs-2 chart.js
Comment

react chartjs 2

import { useState, useEffect, useRef } from "react";
import { Chart as ChartJS, ArcElement, Tooltip, Legend } from "chart.js";
import { Pie } from "react-chartjs-2";

ChartJS.register(ArcElement, Tooltip, Legend);

export const data = {
  labels: ["Case on Hold", "Submitted", "In Production", "Shipped"],
  datasets: [
    {
      label: "# of Votes",
      data: [12, 19, 3, 5],
      backgroundColor: ["#F2CC59", "#BA68C8", "#407BFF", "#E6E5E6"],
      borderColor: ["#F2CC59", "#BA68C8", "#407BFF", "#E6E5E6"],
      borderWidth: 1,
    },
  ],
};

const pieOptions = {
  plugins: {
    legend: {
      display: false,
      labels: {
        font: {
          size: 12,
        },
      },
    },
  },
};

export default function ChartView() {
  const [charView, setChatView] = useState<any>([]);
  const summaryRef: any = useRef(null);

  useEffect(() => {
    setChatView(summaryRef?.current?.legend?.legendItems);
  }, []);

  return (
    <div>
		<Pie data={data} options={pieOptions} ref={summaryRef} /> 
    // coustom label  you need take it else remove code and ref and display: true,
        {charView?.map((data: any, i: number) => (
          <Box display="flex" sx={{ mt: 2 }} key={i}>
                        <Box
              sx={{
                  height: 16,
                  width: 16,
                  background: `${data?.fillStyle}`,
                  borderRadius: 5,
                  mr: 0.5,
                  }}
              />
              	<Typography variant="body2"> {data?.text}</Typography>
              </Box>
		))}
    </div>
  );
}
Comment

react chartjs 2

npm install --save react-chartjs-2 chart.js
Comment

react-chartjs-2

yarn add chart.js react-chartjs-2
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to rotate an array in javascript 
Javascript :: pass parameter to handleclick react 
Javascript :: js then 
Javascript :: connect mysql to node js 
Javascript :: object flatten js 
Javascript :: remove .html from url express js 
Javascript :: delete component angular 
Javascript :: express error middleware 
Javascript :: how to add checked in javascript 
Javascript :: char array to string javascript 
Javascript :: how to print in javascript 
Javascript :: arraylist to json array 
Javascript :: javascript separate string by character 
Javascript :: datatables server side 
Javascript :: rgb javascript 
Javascript :: create a loop that runs through each item in an array 
Javascript :: moment timezone set clock in another timezone 
Javascript :: node js while loop with settimeout 
Javascript :: js datetime format 
Javascript :: move first element to last javascript 
Javascript :: run a local instance of Kibana on docker and connect to elasticsearch 
Javascript :: react-native-config 
Javascript :: javascript push dictionary into array 
Javascript :: js check if array is empty 
Javascript :: how to run react builed version 
Javascript :: how to destroy cookie in javascript 
Javascript :: select distinct on expressions must match initial order by expressions django 
Javascript :: copy text on button click in jquery 
Javascript :: includes method javascript 
Javascript :: Remove First and Last Character 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =