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

PREVIOUS NEXT
Code Example
Javascript :: render text in for loop react in function 
Javascript :: javascript typeof array 
Javascript :: nodejs convert buffer to uint8array 
Javascript :: redux actions.js 
Javascript :: how to disable eval in javascript 
Javascript :: picture in picture remove from videojs 
Javascript :: react native stack transition from right to left 
Javascript :: Ways to Declare Variables in Vanilla JavaScript 
Javascript :: get value from serialized json apex 
Javascript :: how to setup material-table in react 
Javascript :: return array javascript 
Javascript :: fabric js 
Javascript :: recover form data in json 
Javascript :: deploy react to azure : web.config 
Javascript :: inertia-link vuetify 
Javascript :: copying table element to clipboard using javascript 
Javascript :: react useeffect hook 
Javascript :: javascript remove everything after . 
Javascript :: React Javascript Builtin Hooks Import bug 
Javascript :: Setting up an Express project 
Javascript :: add image inside a div on specific position javascript 
Javascript :: javascript ean13 checksum generate 
Javascript :: jquery clone table row 
Javascript :: leaflet js mobile popup not opening 
Javascript :: package.json merger 
Javascript :: asynchronous in javascript 
Javascript :: back button not working when modal open in react native 
Javascript :: how to prevent render in react 
Javascript :: check whether array ascending 
Javascript :: Image preload React 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =