Module: GraphGuru::Helper

Defined in:
lib/graph_guru/helper.rb

Instance Method Summary collapse

Instance Method Details

#line_chart(data, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/graph_guru/helper.rb', line 4

def line_chart(data, options={})

	data = data.map {|key, val| {key: key.to_formatted_s(:db), value: val}}
	format = options[:format] || GraphGuru.date_format
	id = SecureRandom.hex(8)

	styles = ""
	if options.has_key?(:styles)
		styles = options[:styles].inject(styles) { |styles, style|
			styles << "#{style[0]}: #{style[1]};"
		}
	end

	render partial: '/graph_guru/morris_line', locals: {
		format: format,
		styles: styles,
		data: data,
		id: id
	}
end