Incorrect Chartkick y marking

I have chartkick 1.2.0 and gemdate 1.0.4 installed. When I try to do this:

<%= area_chart Match.group_by_day_of_week(:created_at).count, :width=>"700px;", :height=>"150px;" %> 

I get this:

enter image description here

He always gives me the wrong y axis. How can I format it so that it displays "Monday", "Tuesday" ...

My second example, which I also cannot understand, is grouped by the clock per day.

  <% abc=Matches.on_location(@location).group_by{|b| b.created_at.strftime("%H").to_i} %> <% abc.update(abc){|key, v| v.length} %> <%= abc=abc.sort_by{|k,v| k} %> <%= area_chart abc, :width=>"700px;", :height=>"150px;" %> 

What am I doing wrong, that it displays 1:00:00, etc.? I just would like to have numbers, that is: 0, 1, 2, 3 .. 23?

I googled around, checked their documents from top to bottom: http://ankane.imtqy.com/chartkick/ for several hours, and I really don't know what I missed. Any help would be greatly appreciated!

+6
source share
2 answers

This thread on the Chartkick Github indicates that the chart library (Highcharts, in your case?) Makes assumptions about what type of X axis you want. I guess the problem is that the library makes the wrong assumption, so try calling your enter keys in a more understandable format.

In the first example, you can try using the keys "Monday" , "Tuesday" , etc. instead of 0 , 1 , etc .:

 results = Match.group_by_day_of_week(:created_at).count # hash with numeric keys days = %w(Monday Tuesday Wednesday Thursday Friday Saturday Sunday) results = results.inject({}){|a, (k,v)| a.update(days[k] => v); a } # change numeric keys to weekday name 

In the second example, try formatting the date as %H:%M:%S , so it’s more obvious that you need a time axis:

 abc=Matches.on_location(@location).group_by{|b| b.created_at.strftime("%H:%M:%S")} 
+2
source

Unfortunately, there is no way to do this right now. Alternatively, you can try the column chart.

+1
source

Source: https://habr.com/ru/post/956718/


All Articles