2017-06-03 142 views
1

这就是我如何设置数据:图JS数据从零开始

const data = { 
     labels: ['February', 'March'], 
     datasets: [ 
      { 
       label: 'My First dataset', 
       backgroundColor: 'rgba(255,99,132,0.2)', 
       borderColor: 'rgba(255,99,132,1)', 
       borderWidth: 1, 
       hoverBackgroundColor: 'rgba(255,99,132,0.4)', 
       hoverBorderColor: 'rgba(255,99,132,1)', 
       data: [5, 9] 
      } 
     ] 
    }; 

但第一要素设置轴的起点:

enter image description here

但我想它开始从零开始

加入以下没有帮助:

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

我无法在文档上找到其他设置。

我使用这个BTW:https://www.npmjs.com/package/react-chartjs-2

+0

应该肯定的工作。你在哪里添加了选项? –

+0

谢谢,我没有在正确的位置添加选项,但是添加了数据... @ℊααnd和 – shinzou

回答

1

尝试加入分钟到您的选择:

var options = { 
     scales: { 
     yAxes: [{ 
      ticks: { 
      beginAtZero: true, 
      min: 0 
      }  
     }] 
     } 
    }; 

enter image description here

直播Copepen:Chart.js Start at zero

+0

如果仍有问题,您的选项可能未被读取或配置错误,请查看以下选项: https://github.com/gor181/react-chartjs-2/blob/master/example/src/components/mix.js – Keno