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 :: get node degree networkx 
Javascript :: react barcode scanner 
Javascript :: substr method 
Javascript :: electron js web reference to use node 
Javascript :: reduce method in javascript array of bjects 
Javascript :: index localstorage object 
Javascript :: permutation and combination program in javascript 
Javascript :: javascript htmlcollection 
Javascript :: input set variable angular 
Javascript :: sort algorithm for array of objects in js 
Javascript :: how to add the click event into two element in jquery 
Javascript :: date format in javascript 
Javascript :: $out in mongodb 
Javascript :: express-session install 
Javascript :: javscript rename property name 
Javascript :: an arrow function 
Javascript :: find intersection between two object arrays javascript 
Javascript :: momentum 
Javascript :: javascript minute and second to convert seconds 
Javascript :: react routes multiple compoenents 
Javascript :: Javascript using for loop to loop through an array 
Javascript :: Reactjs function exemple useEffect 
Javascript :: setinterval react 
Javascript :: count length of a string javascript 
Javascript :: Example Of LinkedList In JavaScript 
Javascript :: Math max with array js 
Javascript :: hooks developed by react native 
Javascript :: js contenteditable button spacebar 
Javascript :: jquery xpath 
Javascript :: firebase get key value 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =