Class: Chartify::ChartBase

Inherits:
Object
  • Object
show all
Defined in:
lib/chartify/chart_base.rb

Direct Known Subclasses

AreaChart, BarChart, ColumnChart, LineChart, PieChart

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeChartBase

data: array of hash [2013-1-2, hours_remain: 2, estimated_hours_remain: 10, 2013-1-3, hours_remain: 4, estimated_hours_remain: 10, 2013-1-4, hours_remain: 10, estimated_hours_remain: 10]



12
13
14
# File 'lib/chartify/chart_base.rb', line 12

def initialize
  columns, data = [], []
end

Instance Attribute Details

#columnsObject

Returns the value of attribute columns.



5
6
7
# File 'lib/chartify/chart_base.rb', line 5

def columns
  @columns
end

#dataObject

Returns the value of attribute data.



5
6
7
# File 'lib/chartify/chart_base.rb', line 5

def data
  @data
end

#label_columnObject

Returns the value of attribute label_column.



5
6
7
# File 'lib/chartify/chart_base.rb', line 5

def label_column
  @label_column
end

#titleObject

Returns the value of attribute title.



5
6
7
# File 'lib/chartify/chart_base.rb', line 5

def title
  @title
end

Class Method Details

.evaluate_jsObject



34
35
36
# File 'lib/chartify/chart_base.rb', line 34

def self.evaluate_js
  "eval($('script.chart_script').text());"
end

Instance Method Details

#add_row(row) ⇒ Object



16
17
18
# File 'lib/chartify/chart_base.rb', line 16

def add_row(row)
  data << row
end

#render_chart(html_dom_id, options = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/chartify/chart_base.rb', line 20

def render_chart(html_dom_id, options = {})
  api_name = options[:web_api_name] || config.web_api_name.to_s
  class_name = self.class.name.split("::")[1]
  load "chartify/web_chart/#{api_name}/#{class_name.underscore}.rb"
  chart = "Chartify::WebChart::#{api_name.camelize}::#{class_name}".constantize.new
  chart.data, chart.columns, chart.label_column = self.data, self.columns, self.label_column
  html = <<-HTML
  <script type="application/javascript" class="chart_script">
      #{chart.render(html_dom_id)}
  </script>
  HTML
  html.html_safe
end