“Hinzufügen von Tonetiagrammtextexten in React in React” Code-Antworten

Hinzufügen von Tonetiagrammtextexten in React 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;
Mystic Dev

Hinzufügen von Tonetiagrammtextexten in React 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();
       },
     },
   ]}
 />);
Mystic Dev

Hinzufügen von Tonetiagrammtextexten in React 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();
	},
},]
Mystic Dev

Ähnliche Antworten wie “Hinzufügen von Tonetiagrammtextexten in React in React”

Fragen ähnlich wie “Hinzufügen von Tonetiagrammtextexten in React in React”

Weitere verwandte Antworten zu “Hinzufügen von Tonetiagrammtextexten in React in React” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen