【问题标题】:Bar chart from Chart.js not showing the second datasetChart.js 中的条形图未显示第二个数据集
【发布时间】:2019-07-25 22:28:07
【问题描述】:

我有一个来自chart.jsbar chart 有两个数据集,当数据集中的值彼此相距很远时,它会正常显示。但是当它们彼此靠近时,不会显示来自第二个数据集的值

    const options = {
    scales: {
        xAxes: [{
            barPercentage: 0.1,
            categoryPercentage: 0.1,
            barThickness: 20,
            maxBarThickness: 8,
            minBarLength: 7,
            gridLines: {
                offsetGridLines: true
            }
        }]
    }
  };

  const data = {
    datasets: [{
        label: '# of applications',
        data: [30],
        backgroundColor: [
            'rgba(255, 99, 132, 0.2)'
        ],
        borderColor: [
            'rgba(255, 99, 132, 1)'
        ],
        borderWidth: 1
    },{
      label: '# of interviews',
      data: [29],
      backgroundColor: [
          'rgba(54, 162, 235, 0.2)'
      ],
      borderColor: [
          'rgba(54, 162, 235, 1)'
      ],
      borderWidth: 1
  }]
    }

当我在第一个数据集中放 30 个,在第二个数据集中放 29 个时,我只看到第一个

当我将 30 放入第一个数据集中,将 4 放入第二个数据集时,它工作正常,问题在 9 之后开始(所以 10、11 等)

【问题讨论】:

    标签: javascript chart.js bar-chart


    【解决方案1】:

    y 轴从 29 开始,因此“缺失”值(也称为 29)的高度为零。

    添加以下选项以从零开始秤:

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

    【讨论】:

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