简体   繁体   English

图表 JS:设置 Y 轴刻度之间的间距

[英]Chart JS: Set Spacing Between Ticks on Y-Axis

I am building a line chart using ChartJS.我正在使用 ChartJS 构建折线图。 I want to increase the spacing between the vertical tick marks on the Y-Axis.我想增加 Y 轴上垂直刻度线之间的间距。 Here is a slice of the relevant options being passed to ChartJS.这是传递给 ChartJS 的相关选项的一部分。 Is there a property in the ticks section that will allow me to increase the spacing between the ticks, thereby increasing the total height of the chart canvas? ticks部分是否有一个属性可以让我增加刻度之间的间距,从而增加图表画布的总高度?

lineChartOptions = {
    scales: {
      yAxes: [
        {
          id: 'y-axis-0',
          position: 'left',
          ticks: {
              ...    // <-- WHAT OPTION GOES HERE?
          }
        },

Note: It is not an option to simply decrease the height of the canvas using CSS, the canvas stretches to fill the space thereby distorting the chart.注意:不能简单地使用 CSS 降低画布的高度,画布会拉伸以填充空间,从而扭曲图表。

If not much different data you can use this to set range如果没有太多不同的数据,您可以使用它来设置范围

//EXAMPLE DATA [533,743,612,983]
ticks: {
    beginAtZero: false,
    stepSize: 100,
    max: 1000
    min: 500
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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