开发者

How can I create a time-series bar graph in Ruby on Rails with a hash?

开发者 https://www.devze.com 2023-01-22 07:02 出处:网络
I am able to create a time-series \"hash\" using the statistics gem: => #<OrderedHash {\"2010-10-23\"=>2, \"2010-09-22\"=>3, \"2010-09-11\"=>1, \"2010-08-27\"=>1, \"2010-10-15\"=>

I am able to create a time-series "hash" using the statistics gem:

=> #<OrderedHash {"2010-10-23"=>2, "2010-09-22"=>3, "2010-09-11"=>1, "2010-08-27"=>1, "2010-10-15"=>
1, "2010-09-15"=>1, "2010-08-08"=>2, "2010-10-17"=>14, "2010-10-06"=>2, "2010-09-28"=>1, "2010-10-19
"=>1, "2010-09-20"=>1}>

I want to create a simple graph with this data -- I am trying to use the Seer gem but am confused -- it looks like rather than passing in a series, y开发者_C百科ou pass in a method and it runs it live based on the data.

Is there a way I can take data starting with a hash and display it?


I have used highcharts. It is a javascript library but it's really easy to use. Use ruby to get your statistics and then display them with this library.

It does not matter if the data is in a hash or an array. It depends what kinda graph you want. Looking at your data you could just create a line graph. the x-axis would be the time and the y-axis would be the amount.

Then you can just loop over the hash and for each value have the key as the y-value and the value as the x-value.

You will have to create a different hash for each type of data you wanted to store.


Google Charts (http://code.google.com/apis/chart/) is another option, although I have to say that HighCharts looks pretty impressive.

0

精彩评论

暂无评论...
验证码 换一张
取 消