Easily displaying Highcharts graphs with gem style.
latest version: 1.2.2 ChangeLog
To install it, you just need to add it to your Gemfile: gem 'lazy_high_charts'
And then run this to install the javascript files: rails g lazy_high_charts:install
script/plugin install git://github.com/michelson/lazy_high_charts.git ##(for rails 2)
rails plugin install git://github.com/michelson/lazy_high_charts.git ##(for rails 3)
LazyHighCharts now compatible with beta HighStock, http://www.highcharts.com/stock/demo/
About javascript Assets notes:
- add your highcart js to app/assets/javascripts/application.js
//= require highcharts
- you need manually put jquery/highcharts js to public/javascript
- modify your layout html Sample Code:
<%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" %>
<%= javascript_include_tag :highcharts %>
- add gem name in your config/environment.rb
config.gem "lazy_high_charts"
- Done!
@h = LazyHighCharts::HighChart.new('graph') do |f|
f.options[:chart][:defaultSeriesType] = "area"
f.series(:name=>'John', :data=>[3, 20, 3, 5, 4, 10, 12 ,3, 5,6,7,7,80,9,9])
f.series(:name=>'Jane', :data=> [1, 3, 4, 3, 3, 5, 4,-46,7,8,8,9,9,0,0,9] )
end
Without overriding entire option , (only change a specific option index):
@h = LazyHighCharts::HighChart.new('graph') do |f|
#.....
f.options[:chart][:defaultSeriesType] = "area"
f.options[:chart][:inverted] = true
f.options[:legend][:layout] = "horizontal"
f.options[:xAxis][:categories] = ["uno" ,"dos" , "tres" , "cuatro"]
#......
Overriding entire option:
@h = LazyHighCharts::HighChart.new('graph') do |f|
#.....
f.xAxis(:categories => @days.reverse! , :labels=>{:rotation=>-45 , :align => 'right'})
f.chart({:defaultSeriesType=>"spline" , :renderTo => "myRenderArea" , :inverted => true})
#.....
Usage in layout:
<%= javascript_include_tag :highcharts %>
Usage in view:
<%= high_chart("my_id", @h) %>
You can pass in additional javascript into to the view with a block, this will be executed before the high chart is called
<%= high_chart("my_id", @h) do |c| %>
alert('hello')
<%end %>
To include javascript function calls or callbacks you can use the js_code method on your string"function".js_code
:
f.options[:plotOptions] = {
:column => { :events => { :click => %|function() { window.location = "http://www.highcharts.com" }|.js_code } }
}
Just call HighChart Helper this way:
<%= high_stock("my_id", @h) %>
http://www.highcharts.com/ref/
http://www.highcharts.com/license
We're open to any contribution. It has to be tested properly though.
- Fork the project
- Do your changes and commit them to your repository
- Test your changes. We won't accept any untested contributions (except if they're not testable).
- Create an issue with a link to your commits.
Contributer List:
Thanks for Troy & David
- Miguel Michelson Martinez github/michelson
- Deshi Xiao github/xiaods
- Copyright (c) 2011,2012 Deshi Xiao,released under the MIT license
- Copyright (c) 2010 Miguel Michelson Martinez, released under the MIT license