Reputation: 4045
I'm using the High Charts library with rails using the gem found here. Everything is working very nicely, except when I try and add a plotLine to either axis, I can't seem to figure it out. Here are the two options that I've tried so far and their results. Any insight into what is happening would be much appreciated.
Option 1:
chart.yAxis([{title: 'Y-Axis', min: 0, plotLines: {value: 25}])
Result: I get an error in the JavaScript of
Uncaught TypeError: Object #<Object> has no method 'concat'
Specifically, this is referencing the following code in highcharts.js
each((options.plotLines || []).concat(options.plotBands || []), function (plotLineOptions) {
//plotLinesAndBands.push(new PlotLineOrBand(plotLineOptions).render());
axis.addPlotBandOrLine(plotLineOptions);
});
When I pause the execution there the options.plotLines variable is an Object and not an Array, hence no concat method.
Option 2:
chart.yAxis([{title: '', min: 0, plotLines: [{value: 25}]}])
Result: The page fails to render with the following error message from Rails.
You must pass a Hash to Highcharts::Axis::PlotLines. You passed [{:value=>25}]
I'm not sure what to make of this, however, given the API documentation of high charts I would of expected this to work, as I would like to give more than 1 plotLine.
I have also attempted to use chart.renderer.path but that has failed as well. Can someone please explain what is going on, and hopefully suggest a way that I can draw a horizontal line across a High Charts graph in Rails with this gem.
Thanks
Upvotes: 4
Views: 842
Reputation: 4045
I actually figured this out by manipulating the underlying javascript produced by the HighCharts ruby object. Here is the code to do it
chart.yAxis([{title: '', min: 0, plot_lines_replace: plot_lines}])
# Because of a bug in this High Charts rails library, I'm going to have
# to add the plot_lines myself through the javascript
return chart.to_s.gsub("plot_lines_replace", "plotLines").html_safe
This will modify the plot_lines_replace string with plotLines in the javascript and it will work correctly.
Upvotes: 1