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 :: javascript create object empty 
Javascript :: row smaller than the container bootstrap react 
Javascript :: substr javascript 
Javascript :: using datatable 
Javascript :: footer bottom 
Javascript :: js for loop plus number 
Javascript :: Next js Linking example 
Javascript :: javascript inheritence 
Javascript :: updating an array of object in mongoose 
Javascript :: sort list of objects by value node js 
Javascript :: lastindexof 
Javascript :: if () { } 
Javascript :: how to target html elements in javascript 
Javascript :: set date to input date 
Javascript :: unzip array javascript 
Javascript :: javascript mutation observer 
Javascript :: Sort() functions 
Javascript :: html show password 
Javascript :: how to check two different length array values are equal in javascript 
Javascript :: Get last item on js array 
Javascript :: moment iso string 
Javascript :: react-native-bouncy-checkbox 
Javascript :: nuxt auth user info 
Javascript :: string length js 
Javascript :: make a function and return the index of specific character in javascript 
Javascript :: postmark with nodejs 
Javascript :: javascript select audio device 
Javascript :: Usage rate-limiter 
Javascript :: bootstrap carousel dynamic height jquery 
Javascript :: js hex encode 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =