Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react chart.js

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} />    
        {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

chart js react

yarn add react-chartjs-2 chart.js // npm install  react-chartjs-2 chart.js
Comment

react-chartjs-2

yarn add chart.js react-chartjs-2
Comment

PREVIOUS NEXT
Code Example
Javascript :: You provided a `value` prop to a form field without an `onChange` handler 
Javascript :: if statement in react native 
Javascript :: mongodb node js 
Javascript :: dom event 
Javascript :: javascript data 
Javascript :: javascript formdata 
Javascript :: jQuery Stop Animations 
Javascript :: react cors error 
Javascript :: numero random en js 
Javascript :: how to get the difference between two arrays in javascript 
Javascript :: Async return values 
Javascript :: js reverse string 
Javascript :: singleton function javascript 
Javascript :: how to prevent xss attacks in node js 
Javascript :: complete ajax request jquery php call | ajax request 
Javascript :: carbon to moment js conversion 
Javascript :: array.push 
Javascript :: a scroll to div js 
Javascript :: render image in vue 
Javascript :: end session express 
Javascript :: dot geometru three js 
Javascript :: remove 0 after decimal point in javascript 
Javascript :: js reduce 
Javascript :: convert a string array into object using kerys 
Javascript :: jquery datatable update row cell value 
Javascript :: javascript merge two array with spread operator 
Javascript :: javascript fetch APIjson 
Javascript :: regex look behind 
Javascript :: for of in js or for in loop in js 
Javascript :: how to change size of button in react native 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =