Rails + Chartkick:如何更改工具提示的日期格式?

时间:2021-06-06 12:54:12

I am generating the chart (with using Google Chart) this way:

我通过这种方式生成图表(使用Google Chart):

  <%=
    area_chart [{:name => "Sold items", data: @items.group(:created_at).count}], :library => {hAxis: {title: "Period"}, vAxis: {title: "Amounts in UDS"}, title: "History Of Sales"}  
  %>

And the chart is nicely generated, but there's one thing that I am trying to change - the tooltip looks like this: Rails + Chartkick:如何更改工具提示的日期格式?

并且图表很好地生成了,但是我想改变一件事 - 工具提示看起来像这样:

Information in the tooltip are correct, but instead of displaying Oct 19, 2014, 2:00:00 AM I would love to display only Oct 19, 2014.

工具提示中的信息是正确的,但不是显示2014年10月19日,凌晨2:00:00,我希望仅显示2014年10月19日。

Is there any way to do it with Chartkick?

有没有办法用Chartkick做到这一点?

Thank you very much for your time.

非常感谢您的宝贵时间。

2 个解决方案

#1


2  

This works for the x axis:

这适用于x轴:

<%= line_chart @model.group(:created_at).count, library: { hAxis: { format: 'MM/dd' } } %>

#2


0  

You can just use the ruby to change the datetime key into require formats. Example:

您可以使用ruby将datetime键更改为require格式。例:

@items.group("created_at").count.map {|k,v| {k.strftime("%b %d, %Y") => v }}

#1


2  

This works for the x axis:

这适用于x轴:

<%= line_chart @model.group(:created_at).count, library: { hAxis: { format: 'MM/dd' } } %>

#2


0  

You can just use the ruby to change the datetime key into require formats. Example:

您可以使用ruby将datetime键更改为require格式。例:

@items.group("created_at").count.map {|k,v| {k.strftime("%b %d, %Y") => v }}