本文介绍了无法在Charts.js v2.1.4上使y轴从零开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下代码生成图表时,即使设置该选项,我也无法将刻度设置为零。

When using the following code to generate a chart, I am not able to set the scale to begin at zero, even setting that option.

这里是代码()

var simpleChart = new Chart(document.getElementById('chart'), {
    type: 'bar',
    data: {
      labels: ['Online', 'Offline'],
      datasets: [{
        label: "# of servers",
        data: [1, 7],
        backgroundColor: [
            '#009245',
            '#c02a31'
        ]
      }]
    },
    options: {
        title: {
            display: false
        },
        scales: {
            yAxes: [{
                beginAtZero: true
            }]
        }
    }
});

这是一个错误吗?我应该怎么做才能将小数位数设置为真正从0开始?

Is this a bug? What should I do to be able to set the scale to really start at 0?

此外,如何禁用服务器数量 标签是否被渲染?

Also, how can I disable that "# of servers" label from being rendered?

推荐答案

我也遇到了同样的问题。您必须在yAxes定义中定义刻度:

I had the same problems. You have to define "ticks" within the yAxes-definition:

scales: {
          yAxes: [{
            ticks: {
                beginAtZero: true
            }
          }]
}

更新小提琴:

这篇关于无法在Charts.js v2.1.4上使y轴从零开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 11:33