Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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;
Comment

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();
       },
     },
   ]}
 />);
Comment

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();
	},
},]
Comment

PREVIOUS NEXT
Code Example
Javascript :: get element by xpath in javascript 
Javascript :: Autocomplete height adjust in materil ui 
Javascript :: ascii to hex js 
Javascript :: rails is not defined javascript 
Javascript :: how to can i get custom data attribute value in javascript 
Javascript :: clear input from file vue 
Javascript :: react native image disable fade in onload 
Javascript :: js detect scroll 
Javascript :: jshint es6 vscode 
Javascript :: YT.Player is not a constructor 
Javascript :: how to do a classname variable and string react 
Javascript :: jquery append img to div 
Javascript :: javascript prompt for download location 
Javascript :: get current url last part angular 
Javascript :: nextjs absolute import 
Javascript :: disable right click html w3schools 
Javascript :: convert base64 to uint8array javascript 
Javascript :: js remove specific css property 
Javascript :: get message by id discord.js 
Javascript :: how to select second element in jquery 
Javascript :: how to get ip address in javascript 
Javascript :: node js get file name without extension 
Javascript :: ffmpeg thumbnail generator 
Javascript :: js trigger click 
Javascript :: @angular/common 
Javascript :: get uploaded file name in js 
Javascript :: how to update all node libraries 
Javascript :: regular expression for password 
Javascript :: hide element js 
Javascript :: how to take create array using jquery 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =