我已经创建了自定义哈希,但x轴显示为日期。我希望它只显示哈希值(1,2,3等...)。这是我第一次使用chartkick,所以我迷失了为什么会发生这种情况。
显示的内容是2000年1月1日,值为504,2000年2月1日,价值499,3月1日等....
当我将@chart_hash设置为数组时,而不是哈希(这是下面显示的),我在x轴而不是日期得到时间。
application.html.erb
<head>
<title>SampleApp</title>
<%= javascript_include_tag "//www.google.com/jsapi", "chartkick" %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
_chart.html.erb
<%= line_chart @chart_hash %>
@chart_hash
{0=>504, 1=>499, 2=>499, 3=>504, 4=>509, 5=>514, 6=>514, 7=>521.5, 8=>516, 9=>511, 10=>511, 11=>511, 12=>506, 13=>501, 14=>501, 15=>506, 16=>511, 17=>516, 18=>511, 19=>518.5, 20=>522.5}
答案 0 :(得分:0)
答案:在过去,chartkick只能使用日期对象,但现在如果你传递离散选项,它将使用常规数字。
_chart.html.erb
<%= line_chart @chart_hash, discrete: true %>