【问题标题】:How to set vue chartjs begin at zero?如何设置 vue chartjs 从零开始?
【发布时间】:2019-07-30 04:21:41
【问题描述】:

我有使用 vue 的 chartjs 的 Horizo​​ntalBar,我想将比例设置为从零开始,我已经在我的选项中添加了此代码

scales: {
          xAxes: [{
            stacked: true,
            ticks: {
              beginAtZero: true,
              min: 0,
            }
          }]
        },
        scaleBeginAtZero : true,

但它不起作用。

data() {
    return {
      data: {
        labels: this.listLabel,
        datasets: [{
          label: "Usage",
          backgroundColor: "#41946E",
          data: this.listData
        }]
      },
      options: {
        legend: { 
          display: false,

        },
        label:{
          display: true
        },
        scales: {
          xAxes: [{
            stacked: true,
            ticks: {
              beginAtZero: true,
              min: 0,
            }
          }]
        },
        scaleBeginAtZero : true,


      }
    }
  },

我希望它看起来像这样 https://ibb.co/nPfmbDf,但我得到了这样的 https://ibb.co/z7D2tP4,正如你所看到的,设备 5 的值是 10,但它没有显示条形图。

【问题讨论】:

    标签: vue.js vue-chartjs


    【解决方案1】:

    写在选项里面。

    options: {
        scales: {
            xAxes: [{
                ticks: {
                    beginAtZero: true
                }
            }]
        }
    }

    这是来自 Chartjs 的链接 https://www.chartjs.org/docs/latest/developers/updates.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多