I have a pie chart from react-chartjs-2 package, I want the percentage of each segment to be displayed in each area of the pie chart.
Below is my code and the chart I have so far, the desired chart image is also below.
Thank you.
import React from "react";
import { Chart as ChartJS, ArcElement, Tooltip, Legend } from "chart.js";
import { Pie } from "react-chartjs-2";
ChartJS.register(ArcElement, Tooltip, Legend);
export default function PieChart() {
return (
<>
<Pie
options={{
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: { display: false },
tooltip: false,
},
onHover: function (e) {
e.native.target.style.cursor = "pointer";
},
rotation: 270,
events: ["click"],
onClick: function (event, element) {
console.log(element[0].index);
},
}}
data={{
labels: ["Above 60%", "Below 60%"],
datasets: [
{
data: [20, 10],
backgroundColor: ["#3A925D", "#FD7E14"],
borderWidth: 0,
},
],
}}
/>
</>
);
current chart.
desired chart.