react-chartjs-2 icon indicating copy to clipboard operation
react-chartjs-2 copied to clipboard

How I can show the percentage value in doughnut chart?

Open MaiUbeid opened this issue 5 years ago • 6 comments

How I can show the percentage value in the doughnut chart? لقطة الشاشة 2021-04-18 002909

MaiUbeid avatar Apr 17 '21 21:04 MaiUbeid

Think this can help https://chartjs-plugin-datalabels.netlify.app/

Zoniaina avatar Sep 11 '21 11:09 Zoniaina

How I can show the percentage value in the doughnut chart? لقطة الشاشة 2021-04-18 002909

Hi, how do you do this appearance for the chart?

Daniel-Raz-Supersmart avatar Feb 09 '22 18:02 Daniel-Raz-Supersmart

@MaiUbeid w

How I can show the percentage value in the doughnut chart? لقطة الشاشة 2021-04-18 002909

Would you be able to share how did you achieve that rounded doughnut it the correct overlap.

I am trying to achieve exactly what you have there. Thanks

humarkx avatar Feb 12 '22 18:02 humarkx

join to your question and will be glad if you find the answer and let me know

Daniel-Raz-Supersmart avatar Feb 13 '22 09:02 Daniel-Raz-Supersmart

To show percent values, use npm install chart.js chartjs-plugin-datalabels

flymauntains avatar Aug 08 '24 14:08 flymauntains

import React from "react";
import { Doughnut } from "react-chartjs-2";
import { Chart, ArcElement } from "chart.js";
import ChartDataLabels from "chartjs-plugin-datalabels";

Chart.register(ArcElement, ChartDataLabels);

export default function TestChart() {
  const data = {
    datasets: [
      {
        data: [55, 10, 30, 5],
        backgroundColor: ["#8D53BB", "#BF7BF5", "#311746", "#5E3280"],
      },
    ],
  };

  const options = {
    plugins: {
      datalabels: {
        display: true,
        color: '#FF0000',
        formatter: (value, context) => {
          console.log('Test Data Index:', context.dataIndex);
          console.log('Test Value:', value);
          const staticLabels = [55, 10, 30, 5];
          return staticLabels[context.dataIndex];
        },
        anchor: 'center',
        align: 'center',
        font: {
          weight: 'bold',
          size: 16,
        },
      },
    },
  };

  return <Doughnut data={data} options={options} />;
}

flymauntains avatar Aug 08 '24 15:08 flymauntains