Answers for "adding donet chart text center in react"

1

adding donet chart text center in react

function DoughnutChart({ data = {} }) {
 return (
   <Doughnut
     data={format(dataObj)}
     plugins={[
      {
        beforeDraw(chart) {
         const { width } = chart;
         const { height } = chart;
         const { ctx } = chart;
         ctx.restore();
         const fontSize = (height / 160).toFixed(2);
         ctx.font = `${fontSize}em sans-serif`;
         ctx.textBaseline = 'top';
         const { text } = "23";
         const textX = Math.round((width - ctx.measureText(text).width) / 2);
         const textY = height / 2;
         ctx.fillText(text, textX, textY);
         ctx.save();
       },
     },
   ]}
 />);
Posted by: Guest on July-16-2021
1

adding donet chart text center in react

export const plugins = [{
	beforeDraw(chart: any) {
		const { width } = chart;
		const { height } = chart;
		const { ctx } = chart;
		ctx.restore();
		const fontSize = (height / 200).toFixed(2);
		ctx.font = `${fontSize}em sans-serif`;
		ctx.textBaseline = "top";
		const text: string = "Foo- coo";
		const textX = Math.round((width - ctx.measureText(text).width) / 2);
		const textY = height / 2.4;
		ctx.fillText(text, textX, textY);
		ctx.save();
	},
},]
Posted by: Guest on July-16-2021
1

adding donet chart text center in react

import { Doughnut } from "react-chartjs-2";

function DoughnutChart() {

 const data = {...}

 const options = {...}

 const plugins = [{
     beforeDraw: function(chart) {
      var width = chart.width,
          height = chart.height,
          ctx = chart.ctx;
          ctx.restore();
          var fontSize = (height / 160).toFixed(2);
          ctx.font = fontSize + "em sans-serif";
          ctx.textBaseline = "top";
          var text = "Foo-bar",
          textX = Math.round((width - ctx.measureText(text).width) / 2),
          textY = height / 2;
          ctx.fillText(text, textX, textY);
          ctx.save();
     } 
   }]



  return (
   
        <Doughnut 
          type="doughnut" 
          data={data} 
          options{options} 
          plugins={plugins} 
         />
  );
}

export default DoughnutChart;
Posted by: Guest on July-16-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language