Rails chartkick: want only integer values on axes. Use discrete or something else?

佐手、 提交于 2019-12-03 07:28:40

The discrete option applies only to the 'major axis' and is for a discrete axis. There's a difference between discrete and continuous axises that you should read up on.

And I just read the configuration options. Apparently you can pass a ticks option to each axis. And the ticks are markers. You could get the minimum and maximum value for each range from your data and then spread it out with a 1 integer interval.

Thus the following should work for you:

data = [[1,1],[2,3],[3,5],[4,8],[6,4],[7,2]]

x_values = data.map(&:first)
x_range = (x_values.min)..(x_values.max)

y_values = data.map(&:last)
y_range = (y_values.min)..(y_values.max)

library_options = {
  width: 600,
  hAxis: {ticks: x_range.to_a},
  vAxis: {ticks: y_range.to_a}
  # to_a because I don't know if Range is acceptable input
}

line_chart(data, {library: library_options})

For more options, take a look at Google Chart's configuration options for line charts.

Just try this.: library: { yAxis: {allowDecimals: false } }

Source.: https://github.com/ankane/chartkick/issues/269

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