Class: RailsCharts::PieChart

Inherits:
LineChart show all
Defined in:
lib/rails_charts/pie_chart.rb

Direct Known Subclasses

DonutChart

Constant Summary

Constants inherited from BaseChart

BaseChart::CHART_JS_PATTERN

Instance Attribute Summary

Attributes inherited from BaseChart

#chart_id, #container_id, #data, #debug, #height, #klass, #locale, #options, #other_options, #renderer, #style, #theme, #vertical, #width

Instance Method Summary collapse

Methods inherited from LineChart

#initialize, #x, #y

Methods inherited from BaseChart

#axises, #initialize, #js_code, #option

Constructor Details

This class inherits a constructor from RailsCharts::LineChart

Instance Method Details

#build_optionsObject



8
9
10
# File 'lib/rails_charts/pie_chart.rb', line 8

def build_options
  super.except(:xAxis, :yAxis)
end

#defaultsObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rails_charts/pie_chart.rb', line 34

def defaults
  {
    tooltip: {
      item: {
        trigger: 'item',
      },      
    },
    series: {
      radius: '70%',
    },
    emphasis: {
      itemStyle: {
        shadowBlur: 10,
        shadowOffsetX: 0,
        shadowColor: 'rgba(0, 0, 0, 0.5)'
      }
    }
  }
end

#generate_series_optionsObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rails_charts/pie_chart.rb', line 12

def generate_series_options
  if data[0].is_a?(Hash)
    {
      data: data,
      type: type
    }
  else
    {
      data: data.map{|k, v| {name: k, value: v} },
      type: type
    }
  end
end

#typeObject



4
5
6
# File 'lib/rails_charts/pie_chart.rb', line 4

def type
  'pie'
end

#x_axisObject



26
27
28
# File 'lib/rails_charts/pie_chart.rb', line 26

def x_axis
  []
end

#y_axisObject



30
31
32
# File 'lib/rails_charts/pie_chart.rb', line 30

def y_axis
  []
end