简体   繁体   中英

ChartJS Y Axis scale odd

I have a simple line chart built using ChartJS. The Y axis scale values are odd. The data set I'm testing with has values of all 0 and a single value of 1 . The Y axis ChartJS builds is from 0 to 1. The values start at 0 and proceed up in tenths.. (ex. 0, 0.1, 0.2, etc).. The problem is, when it get's to 0.3, the label is 0.030,000,000,000,000,004 . It does it again on the 0.6 and 0.7 increments.

My options block follows.

responsive: true,
maintainAspectRatio: false,
scales: {
yAxes: [{
        //type: 'logarithmic',
        ticks: {
            beginAtZero: true,
            precision: 1,
            callback: function (label, index, labels) {
                return label.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
            }
        }
    }
]
},
tooltips: {
mode: 'index',
intersect: false,
callbacks: {
    label: function (label, data) {
        return ' ' + data.datasets[label.datasetIndex].label + ' ' + label.yLabel.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    }
}
},
legend: {
    display: true
}

在此处输入图片说明

我们在 ChartJS 版本 2.4 上,升级到最新版本,截至今天 2.9.3,修复了规模问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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