Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/chartkick/core_ext.rb

Instance Method Summary collapse

Instance Method Details

#chart_jsonObject



17
18
19
20
21
22
23
24
25
# File 'lib/chartkick/core_ext.rb', line 17

def chart_json
  if (key = keys.first) && key.is_a?(Array) && key.size == 2
    group_by { |k, _v| k[0] }.map do |name, data|
      {name: name, data: data.map { |k, v| [k[1], v] }}
    end
  else
    to_a
  end.to_json
end