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



32
33
34
# File 'lib/chartify/chart_base.rb', line 32

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
# File 'lib/chartify/chart_base.rb', line 20

def render_chart(html_dom_id, options = {})
  api_name = fetch_api_name(options)
  chart = instantiate_chart(api_name)
  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