0

我在我的数据值中添加逗号,如下所示:

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

?

4

1 回答 1

2

使用您的手工addCommas功能应该可以解决问题:

options: {
    scales: {
        yAxes: [{
            ticks: {
                userCallback: function(item) {
                    return addCommas(item);
                },
            }
        }]
    }
}
于 2016-10-03T22:30:46.390 回答