Skip to content

Instantly share code, notes, and snippets.

@darmawan01
Created March 14, 2023 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darmawan01/2eb098f0a6f07965b42b7f523dffcb78 to your computer and use it in GitHub Desktop.
Save darmawan01/2eb098f0a6f07965b42b7f523dffcb78 to your computer and use it in GitHub Desktop.
Example of making text inside dougnat chart js
```
<Doughnut
data={data}
options={{
cutout: '70%',
}}
plugins={[
{
id: "title",
beforeDraw: function (chart) {
var width = chart.width,
height = chart.height,
ctx = chart.ctx;
ctx.restore();
ctx.font = "500 24px Inter";
ctx.textBaseline = "top";
var text = "102k",
textX = Math.round((width - ctx.measureText(text).width) / 2),
textY = height / 2.4;
ctx.fillStyle = "rgba(58, 53, 65, 0.87)";
ctx.fillText(text, textX, textY);
ctx.save();
}
},
{
id: "subTitle",
beforeDraw: function (chart) {
var width = chart.width,
height = chart.height,
ctx = chart.ctx;
ctx.restore();
ctx.font = "400 14px Inter";
ctx.textBaseline = "top";
var text = "Total Issuance",
textX = Math.round((width - ctx.measureText(text).width) / 2),
textY = height / 1.8;
ctx.fillStyle = "rgba(58, 53, 65, 0.68)";
ctx.fillText(text, textX, textY);
ctx.save();
}
},
]}
/>
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment