Sha256: 13479de75bf7f10abf68515e8cfae68852fef9dd5a5bc2780504219ac5c7eac3
Contents?: true
Size: 1.16 KB
Versions: 1
Compression:
Stored size: 1.16 KB
Contents
module Chartkick module Helper def line_chart(data_source, options = {}) chartkick_chart "LineChart", data_source, options end def pie_chart(data_source, options = {}) chartkick_chart "PieChart", data_source, options end def column_chart(data_source, options = {}) chartkick_chart "ColumnChart", data_source, options end private def chartkick_chart(klass, data_source, options, &block) @chartkick_chart_id ||= 0 options = options.dup element_id = options.delete(:id) || "chart-#{@chartkick_chart_id += 1}" height = options.delete(:height) || "300px" # don't quote font-family names due to rails escaping div_tag = content_tag :div, :id => element_id, :style => "height: #{height}; text-align: center; color: #999; line-height: #{height}; font-size: 14px; font-family: Lucida Grande, Lucida Sans Unicode, Verdana, Arial, Helvetica, sans-serif;" do concat "Loading..." end script_tag = javascript_tag do concat "new Chartkick.#{klass}(#{element_id.to_json}, #{data_source.to_json}, #{options.to_json});".html_safe end div_tag + script_tag end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
chartkick-1.0.1 | lib/chartkick/helper.rb |