【发布时间】:2021-05-27 20:22:32
【问题描述】:
我在 Ruby on Rails 中使用 chartkick 和 chart.js。我查看了文档和一些问题,但找不到任何解决问题的方法。
我在 html.erb 文件中设置我的图表,如下所示:
<%=
line_chart $hash_chart,
options: {
max: $value.max+5,
min: $value.min-5,
allowDecimals: false,
colors: color_line,
xtitle: "Title of x axis",
ytitle: "Title of y axis",
discrete: true,
points: false,
width: "500px",
height: "500px",
scales: {
yAxes: [{
distribution: 'linear'
}],
xAxes: [{
distribution: 'linear',
type: 'category', (part of a configuration attempt)
categories: $time, (part of a configuration attempt)
ticks: {
stepSize: 10
}
}]
}
}
%>
高度参数之前的设置有效,但缩放设置无效。这个问题的答案正是我所做的(根据 Chart.js 的文档),但没有奏效:Force display of ticks on xAxes using chartkick gem and chart.js。我也尝试将此设置放在库大括号中。
基本上,我想在 x 轴上设置刻度并只显示我的数据数组的一些标签。是否可以格式化(使用这种类型的文件)?
【问题讨论】:
-
应该将高度和宽度的值引用为字符串吗?
-
是的,我写错了,对不起。它们需要是字符串。我编辑了问题。
标签: html ruby-on-rails chart.js chartkick