How to set Axis step in Google Chart?

佐手、 提交于 2020-01-09 19:30:08

问题


I'm wondering how to set axis step in a google chart built from JavaScript? I use this to set min and max:

vAxis: {
title: 'temps (ms)',
    viewWindowMode: 'explicit',
    viewWindow: {
        max: 180,
        min: 0
    },
}

And I need to add an other constraint to fix vertical step to 0.1 for example.


回答1:


Finally I found a trick using :

     vAxis: {
        title: 'temps (ms)',
        viewWindowMode: 'explicit',
        viewWindow: {
          //max: 180,
          min: 0,
        },
        gridlines: {
          count: 10,
        }
      }

It don't set steps but instead, tell that

max / (nb steps) = count (here it's 10)

So for example with max set to 180, each steps will have a value of 18 using count: 10.




回答2:


You can do it with ticks:

vAxis: {
    title: 'temps (ms)',
    viewWindow: {
        min: 0,
        max: 180
    },
    ticks: [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180] // display labels every 10
}



回答3:


I essentially did what alain did, calculating the max value, multiplying it by 1.1 (to account for the padding above the max element on the chart) and dividing it by the steps I wanted to give me the steps I needed.

vAxis: {
  title: 'vAxis',
  minValue: 0,
  gridlines: {
    count: Math.ceil(max * 1.1 / interval) // try to pick the correct number to create intervals of 50000 
  }
}

where max is the max value and interval is the desired interval. This has not been thoroughly tested, so the constant of 1.1 and using Math.ceil may need to be tweaked.



来源:https://stackoverflow.com/questions/9104925/how-to-set-axis-step-in-google-chart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!