Module: Echarts::BinarySeries

Defined in:
lib/echarts/binary_series.rb

Class Method Summary collapse

Class Method Details

.get_config(x, values, title, subtitle, xLabel, yLabel) ⇒ Object



3
4
5
6
7
8
9
10
11
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
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/echarts/binary_series.rb', line 3

def self.get_config(x, values, title, subtitle, xLabel, yLabel)
  Rails.logger.debug("X: #{x}\nValues: #{values}")
  {
    grid: {
      top: 80,
    },
    title: {
      text: title,
      subtext: subtitle,
    },
    toolbox: {
      top: 'middle',
      right: 5,
      orient: "vertical",
      feature: {
        saveAsImage: {},
        dataView: {},
        dataZoom: {},
        restore: {},
      },
    },
    tooltip: {
      trigger: "axis",
    },
    xAxis: {
      type: "category",
      data: x,
      name: xLabel,
    },
    yAxis: {
      type: "value",
      name: yLabel
    },
    # Data series is always 1 for each element in x array
    # The color of the bar (the graph is a bargraph) depends 
    # on the value, if it's 1, then it's red, otherwise it's green
    series: [
      {
        name: "Values",
        data: x.map.with_index { |_, index| { value: 1, itemStyle: { color: values[index].to_i == 1 ? 'tomato' : 'limegreen' } } },
        type: "bar"
      },
    ],
  }
end