Module: Chartnado::Helpers::Chart

Includes:
Chartkick::Helper, Chartkick::Remote::Helper
Defined in:
lib/chartnado/helpers/chart_helper.rb

Instance Method Summary collapse

Instance Method Details

#line_chart_with_chartnado(*args, **options, &block) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/chartnado/helpers/chart_helper.rb', line 58

def line_chart_with_chartnado(*args, **options, &block)
  Chartnado::Renderer.new(self, block) do |chartkick_options, json_options, data_block|
    new_options = chartkick_options.reverse_merge(
      library: {
        curveType: "none",
        pointSize: 2,
        focusTarget: 'category'
      })
    line_chart_without_chartnado(**new_options) do
      data_block.call(**json_options)
    end
  end.render(*args, **options)
end

#pie_chart_with_chartnado(*args, **options, &block) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/chartnado/helpers/chart_helper.rb', line 38

def pie_chart_with_chartnado(*args, **options, &block)
  Chartnado::Renderer.new(self, block) do |chartkick_options, json_options, data_block|
    new_json_options = json_options.reverse_merge(show_total: true)
    new_options = chartkick_options.reverse_merge!(
      library: {
        series: {
          0 => {
            lineWidth: 0,
            pointSize: 0,
            visibleInLegend: false
          }
        }
      }
    ) if new_json_options[:show_total]
    pie_chart_without_chartnado(**new_options) do
      data_block.call(new_json_options)
    end
  end.render(*args, **options)
end

#stacked_area_chart(*args, **options, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/chartnado/helpers/chart_helper.rb', line 12

def stacked_area_chart(*args, **options, &block)
  Chartnado::Renderer.new(self, block) do |chartkick_options, json_options, data_block|
    new_options = chartkick_options.reverse_merge(
      stacked: true,
      library: {
        focusTarget: 'category'
      }
    )
    new_json_options = json_options.reverse_merge(show_total: true, reverse_sort: true)
    new_options.reverse_merge!(
      library: {
        series: {
          0 => {
            lineWidth: 0,
            pointSize: 0,
            visibleInLegend: false
          }
        }
      }
    ) if new_json_options[:show_total]
    area_chart_without_chartnado(**new_options) do
      data_block.call(new_json_options)
    end
  end.render(*args, **options)
end