Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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();
	},
},]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #adding #donet #chart #text #center #react
ADD COMMENT
Topic
Name
1+3 =