我在我的数据值中添加逗号,如下所示:
ctx.fillText(addCommas(dataset.data[i]), model.x, y_pos);
. . .
function addCommas(nStr) {
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}
...但是条形图 y 轴上的“上下文”值是“原始”(无逗号),如下所示:
通过添加逗号以便阅读:
1,900,000
1,800,000
1,700,000
1,600,000
1,500,000
?