Last active
August 29, 2015 13:57
-
-
Save eLafo/9748662 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Chart | |
def time_data_with_irregular_intervals(series, *args) | |
options = args.extract_options! | |
LazyHighCharts::HighChart.new('basic_line') do |f| | |
f.chart({ type: 'spline', | |
marginRight: 130, | |
marginBottom: 60 }) | |
f.title({ | |
text: options[:title], | |
x: -20 | |
}) | |
f.xAxis({ | |
type: 'datetime', | |
labels: { | |
dateTimeLabelFormats: { | |
month: '%e. %b', | |
year: '%b' | |
}, | |
step: 2 | |
}, | |
tickPixelInterval: 150, | |
tickColor: 'gray', | |
tickLength: 10, | |
tickWidth: 2, | |
tickPosition: 'outside' | |
}) | |
f.yAxis({ | |
title: { | |
text: options[:y_title] | |
}, | |
min: 0, | |
max: options[:max_value], | |
plotLines: [{ | |
value: options[:max_value], | |
color: options[:color_line], | |
width: 3 | |
}] | |
}) | |
f.legend({ | |
layout: 'vertical', | |
align: 'right', | |
verticalAlign: 'top', | |
x: -10, | |
y: 100, | |
borderWidth: 0 | |
}) | |
f.tooltip({ | |
dateTimeLabelFormats: { | |
month: '%e. %b', | |
year: '%b' | |
}, | |
#crosshairs: [true, true], | |
crosshairs: [{width: 2, | |
color: 'gray', | |
dashStyle: 'shortdot'}, | |
{width: 2, | |
color: 'gray', | |
dashStyle: 'shortdot'}], | |
formatter: send(options[:tooltip_formatter], options[:tooltip_data]) | |
}) | |
f.series(series) | |
end | |
end | |
private | |
def cash_formatter(data) | |
return unless data | |
<<-JS.js_code | |
function() { | |
var movements = #{data.to_json}; | |
var s = '<b>' + Highcharts.dateFormat('%d. %B %Y',this.x); + '</b>'; | |
for (var i = 0; i < movements[this.x].length; i++){ | |
var movement = movements[this.x][i]; | |
s += '<br/>' + movement.name + ': <b>' + Highcharts.numberFormat(movement.amount, 2) + '</b><br/>'; | |
} | |
s += '<b>' + Highcharts.numberFormat(this.y, 2) + '</b>'; | |
return s; | |
} | |
JS | |
end | |
def credit_line_formatter(data) | |
return unless data | |
<<-JS.js_code | |
function() { | |
var movements = #{data.to_json}; | |
var s = '<b>' + Highcharts.dateFormat('%d. %B %Y',this.x); + '</b>'; | |
for (var i = 0; i < movements[this.x].length; i++){ | |
var movement = movements[this.x][i]; | |
s += '<br/>' + 'disposed' + ': <b>' + Highcharts.numberFormat(movement.amount, 2) + '</b><br/>'; | |
} | |
s += '<b>' + Highcharts.numberFormat(this.y, 2) + '</b>'; | |
return s; | |
} | |
JS | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment