Module: Html5jpGraphsHelper
- Defined in:
- lib/html5jp_graphs_helper.rb
Overview
Html5jpGraphsHelper
Instance Method Summary collapse
-
#line_chart(resource, options = {}, html_options = {}) ⇒ Object
Draw a line chart using Html5jp radar chart (www.html5.jp/library/graph_line.html).
-
#pie_chart(resource, options = {}, html_options = {}) ⇒ Object
Draw a pie chart using HTML5jp pie chart (www.html5.jp/library/graph_circle.html).
-
#radar_chart(resource, options = {}, html_options = {}) ⇒ Object
Draw a radar chart using Html5jp radar chart (www.html5.jp/library/graph_radar.html).
-
#vertical_bar_chart(resource, options = {}, html_options = {}) ⇒ Object
-
each - to supply record objects.
-
Instance Method Details
#line_chart(resource, options = {}, html_options = {}) ⇒ Object
Draw a line chart using Html5jp radar chart (www.html5.jp/library/graph_line.html).
ex.
<%= line_chart [['accesses', 520, 340, 804, 602], ['clicks', 101, 76, 239, 321]] %>
The first argument ‘resource’ can be one of the following forms.
- ‘accesses’, 520, 340, 804, 602
- [‘accesses’, 520, 340, 804, 602], [‘clicks’, 101, 76, 239, 321]
-
Any other object which has required methods as follows;
-
each - to supply record objects.
-
items - If :x option does not exist and your resource object has items method, it is called to get :x. You can change the method name by :items_method option.
-
scales - If :y option does not exist and your resource object has scales method, it is called to get :y. You can change the method name by :scales_method option
-
max_scale - Would be used as :yMax option if it exists.
-
min_scale - Would be used as :yMin option if it exists.
-
The record object shoud have methods as follows.
-
label - Like ‘accesses’ in the example. You can use other method if you specify :label_method option.
-
values - Like [520, 340, 804, 602] in the example. You can use other method if you specify :values_method option.
-
-
Additionaly, the following options are available.
-
:canvas_id - element id of the canvas. Default is ‘line_chart’. Note that all rader charts in one page sould have unique canvas_ids.
-
:width - The width of the canvas. Default is 400.
-
:height - The height of the canvas. Default is 300.
-
All options in www.html5.jp/library/graph_line.html. ex. ‘yMax’ or :yMax.
And you can use html_options for the top level div.
86 87 88 89 90 91 |
# File 'lib/html5jp_graphs_helper.rb', line 86 def line_chart(resource, = {}, = {}) = {:width => 400, :height => 300, :canvas_id => 'line_chart'}.merge(.symbolize_keys) output = canvas(, ) output << "\n" output << line_chart_js(resource, ) end |
#pie_chart(resource, options = {}, html_options = {}) ⇒ Object
Draw a pie chart using HTML5jp pie chart (www.html5.jp/library/graph_circle.html).
ex.
<%= pie_chart([["very good", 400], ["good", 300], ["bad", 100], ["very bad", 300]]) %>
The first argument ‘resource’ can be one of the following forms.
- [“very good”, 400], [“good”, 300], [“bad”, 100], [“very bad”, 300, “red”]
-
Any other object which has required methods as follows;
-
each - to supply record objects.
-
The record object shoud have methods as follows.
-
label - Like ‘very good’ in the example. You can use other method if you specify :label_method option.
-
value - Like 400 in the example. You can use other method if you specify :value_method option.
-
color - Like “red” in the example. You can use other method if you specify :color_method option. This is optional.
-
-
Additionaly, the following options are available.
-
:canvas_id - element id of the canvas. Default is ‘pie_chart’. Note that all rader charts in one page sould have unique canvas_ids.
-
:width - The width of the canvas. Default is 400.
-
:height - The height of the canvas. Default is 300.
-
:sort - If true, sort the records in descending order. Default is false.
-
All options in www.html5.jp/library/graph_circle.html. ex. ‘startAngle’ or :startAngle.
And you can use html_options for the top level div.
113 114 115 116 117 118 |
# File 'lib/html5jp_graphs_helper.rb', line 113 def pie_chart(resource, = {}, = {}) = {:width => 400, :height => 300, :canvas_id => 'pie_chart', :sort => false}.merge(.symbolize_keys) output = canvas(, ) output << "\n" output << pie_chart_js(resource, ) end |
#radar_chart(resource, options = {}, html_options = {}) ⇒ Object
Draw a radar chart using Html5jp radar chart (www.html5.jp/library/graph_radar.html).
ex.
<%= radar_chart [['review1', 5, 4, 3], ['review2', 3, 5, 2]], :aCap => ['price', 'style', 'sound'] %>
The first argument ‘resource’ can be one of the following forms.
- ‘my review’, 1, 2, 3, 4
- [‘my review’, 1, 2, 3, 4], [‘all reviews’, 2, 3, 4, 3]
-
Any other object which has required methods as follows;
-
each - to supply record objects.
-
items - If :aCap option does not exist and your resource object has items method, it is called to get :aCap. You can change the method name by :items_method option.
-
The record object shoud have methods as follows.
-
label - Like ‘my review’ in the example. You can use other method if you specify :label_method option.
-
values - Like [1, 2, 3, 4] in the example. You can use other method if you specify :values_method option.
-
color - If :faceColors option does not exist and your record object has color method, it is used for :faceColors. You can change the method name by :color_method option.
-
-
Additionaly, the following options are available.
-
:canvas_id - element id of the canvas. Default is ‘rader_chart’. Note that all rader charts in one page sould have unique canvas_ids.
-
:width - The width of the canvas. Default is 400.
-
:height - The height of the canvas. Default is 300.
-
All options in www.html5.jp/library/graph_radar.html. ex. ‘aMax’ or :aMax.
And you can use html_options for the top level div.
56 57 58 59 60 61 |
# File 'lib/html5jp_graphs_helper.rb', line 56 def radar_chart(resource, = {}, = {}) = {:width => 400, :height => 300, :canvas_id => 'reader_chart'}.merge(.symbolize_keys) output = canvas(, ) output << "\n" output << rader_chart_js(resource, ) end |
#vertical_bar_chart(resource, options = {}, html_options = {}) ⇒ Object
-
each - to supply record objects.
-
items - If :x option does not exist and your resource object has items method, it is called to get :x. You can change the method name by :items_method option.
-
scales - If :y option does not exist and your resource object has scales method, it is called to get :y. You can change the method name by :scales_method option
-
max_scale - Would be used as :yMax option if it exists.
-
The record object shoud have methods as follows.
-
label - Like ‘accesses’ in the example. You can use other method if you specify :label_method option.
-
values - Like [520, 340, 804, 602] in the example. You can use other method if you specify :values_method option.
-
color - If :barColors option does not exist and your record object has color method, it is used for :barColors. You can change the method name by :color_method option.
-
-
Additionaly, the following options are available.
-
:canvas_id - element id of the canvas. Default is ‘line_chart’. Note that all rader charts in one page sould have unique canvas_ids.
-
:width - The width of the canvas. Default is 400.
-
:height - The height of the canvas. Default is 300.
-
All options in www.html5.jp/library/graph_vbar.html. ex. ‘backgroundColor’ or :backgroundColor.
And you can use html_options for the top level div.
27 28 29 30 31 32 |
# File 'lib/html5jp_graphs_helper.rb', line 27 def (resource, = {}, = {}) = {:width => 400, :height => 300, :canvas_id => 'vertical_bar_chart'}.merge(.symbolize_keys) output = canvas(, ) output << "\n" output << (resource, ) end |