简体   繁体   English

甜甜圈图内的粗体文本(chart.js)

[英]Bold text inside doughnut chart (chart.js)

I'm trying to set bold text inside my doughnut chart(using chart.js) 我正在尝试在我的甜甜圈图中设置粗体文本 (使用chart.js)

And below code is working well, but -fontStyle and fontWeight-these are not working at all. 下面的代码运行良好,但是-fontStyle和fontWeight-这些根本不起作用。

How can I change my center text to bold? 如何将中心文本更改为粗体?

let ctx = chart.chart.ctx;

ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.font = '3vh Montserrat';
ctx.fontStyle = 'bold';  // not working!
ctx.fontWeight = '900';  // not working!

http://jsfiddle.net/wh5kcqzy/3/ http://jsfiddle.net/wh5kcqzy/3/

Plz see HTML canvas font Property. 请查看HTML画布字体属性。

The JavaScript syntax: context.font="italic small-caps bold 12px arial"; JavaScript语法:context.font =“ italic small-caps bold 12px arial”;

Reference: https://www.w3schools.com/tags/canvas_font.asp 参考: https : //www.w3schools.com/tags/canvas_font.asp

In your case just replace: 在您的情况下,只需替换:

let ctx           =   chart.chart.ctx;
let fontSize      =   (height / 100).toFixed(2);

ctx.textAlign     =   'center';
ctx.textBaseline  =   'middle';
ctx.font          =   "bold " + fontSize + "em Montserrat";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM