3

I got a line_chart form a punch of data.

<%= line_chart @images.group(:imagedatetime).average(:exposureindex), library: {discrete: true, pointSize: 1, lineWidth: 0, hAxis: {type: "category"}} %>

and now i want to have an extra line which goes through the whole chart and indicates me the average value of my data. Does anybody know if there is an option for that? I tried to draw a chart with two lines where as one line is made up from the actual data and the other line is made from a single value repeated as many times to draw a line. But I just couldn't figure out how to put that into code...

Does anyone has a clue?

Da Mks
  • 31
  • 6

3 Answers3

2

I had the same problem, and I found a solution. Here is my example:

def systolic
  data.group_by_day(:date).maximum(:systolic)
end

def ideal_diastolic
  Hash[data.map{|data| [Date.parse(data.date.to_s), 90]}]
end

I have some health data objects, with user heart pressure. I wanted to show also a line with ideal value of it. I use class called Statistics that contains presented methods. Both methods creates a Hash {date => value} but in second one value is constant. To generate graph with two lines do this:

 = line_chart [ {name: "systolic", data: @statistics.systolic}, {name:"ideal systolic", data: @statistics.ideal_systolic}]
tommybernaciak
  • 390
  • 2
  • 17
0

i had the same problem and i ended up using highchart, and there is a great gem lazyhighchart that helps you create amazing js graphs in rails env

  • Hmm, not really the answer i had hoped for, but this lazyhighchart looks pretty good too. I'll give it a try asap. Thanks! – Da Mks Dec 11 '14 at 13:50
0
line_chart   [ {name: "Registered users", data: User.get_users_only.order("DATE(created_at)").group("DATE(created_at)").count}, {name:"Guest users", data: User.get_guest_users_only.order("DATE(created_at)").group("DATE(created_at)").count}]  
Milind
  • 4,535
  • 2
  • 26
  • 58