Created
March 14, 2023 06:06
-
-
Save darmawan01/2eb098f0a6f07965b42b7f523dffcb78 to your computer and use it in GitHub Desktop.
Example of making text inside dougnat chart js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` | |
<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