Using tall maps with rails not displaying plotLines

I use the High Charts library with rails using the gem found here . Everything works very beautifully, except when I try to add a storyline to any axis, I can’t figure it out. Here are two options I've tried so far, and their results. Any understanding of what was going on would be greatly appreciated.

Option 1:

chart.yAxis([{title: 'Y-Axis', min: 0, plotLines: {value: 25}]) 

Result: I get an error in JavaScript

 Uncaught TypeError: Object #<Object> has no method 'concat' 

In particular, this refers to the following code in the highcharts.js file

 each((options.plotLines || []).concat(options.plotBands || []), function (plotLineOptions) { //plotLinesAndBands.push(new PlotLineOrBand(plotLineOptions).render()); axis.addPlotBandOrLine(plotLineOptions); }); 

When I pause execution, the options.plotLines variable is an object, not an array, so it is not a concat method.

Option 2:

 chart.yAxis([{title: '', min: 0, plotLines: [{value: 25}]}]) 

Result: The page cannot display 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 do with this, given the API documentation for high graphics. I expected this to work, as I would like to give more than 1 plotLine.

I also tried using chart.renderer.path, but that also failed. Can someone explain what is happening and hopefully suggest a way that I can draw a horizontal line on the High Charts chart in Rails with this stone.

thanks

+4
source share
1 answer

I really understood this by manipulating the underlying javascript created by the Ruby HighCharts object. Here is the code to do this

 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 change the plot_lines_replace line using plotLines in javascript and will work correctly.

+1
source

Source: https://habr.com/ru/post/1444713/


All Articles