Sha256: a8ea93e9b746227e3967cba1f874127eea4b1acf7859063685689ddc27ded468

Contents?: true

Size: 1.14 KB

Versions: 5

Compression:

Stored size: 1.14 KB

Contents

module Echarts
  module BinarySeries
    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: {
          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
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
thecore_ui_commons-3.2.9 lib/echarts/binary_series.rb
thecore_ui_commons-3.2.8 lib/echarts/binary_series.rb
thecore_ui_commons-3.2.7 lib/echarts/binary_series.rb
thecore_ui_commons-3.2.6 lib/echarts/binary_series.rb
thecore_ui_commons-3.2.5 lib/echarts/binary_series.rb