I am creating a HighChart with a plotLine in it. The plotLine has a fixed value, while the data can vary between charts.
HighChart scales the y-axis automatically based on the maximum value of data, but it doesn't consider the plotLine's value in its calculations.
Hence, if the data range encompasses the plotLine value, the plotLine gets shown, but gets cropped out of the viewport if not.
Example:
$(function () { $(document).ready(function() { var chart = new Highcharts.Chart({ chart: { renderTo: 'container', type: 'column' }, title: { text: 'Dummy Data by Region' }, xAxis: { categories: ['Africa', 'America', 'Asia'] }, yAxis: { plotLines:[{ value:450, color: '#ff0000', width:2, zIndex:4, label:{text:'goal'} }] }, series: [{ name: 'Year 1800', data: [107, 31, 650] }] }); }); });
JSFiddle for above code: http://jsfiddle.net/4R5HH/3/
The goal line (in red) is shown for the default data, but if I change the data to [107, 31, 250], then the plotLine goes out of the graph viewport and hence becomes invisible.
An array of lines stretching across the plot area, marking a specific value on one of the axes. In styled mode, the plot lines are styled by the . highcharts-plot-line class in addition to the className option.
A "Plotband" repesent a rectangualr area in the graph that can be given a specific pattern ranging from 3D grid to simple horizntal grid lines. A Plot band is then added to the graph via the Graph::AddBand() method. See also related classes: Graph.
One other option that does not introduce data points:
yAxis: { minRange:450, min:0, plotLines:[{ value:450, color: '#ff0000', width:2, zIndex:4, label:{text:'goal'} }] },
This sets the minimum for the yAxis to 0 (this is unlikely to be false in this case) and the minimum Range to 450.
See updated fiddle.
You need to add in a point to you chart but disable the marker. I added a new series with scatter plot type and its value equal to the goal value:
{ name: 'Goal', type: 'scatter', marker: { enabled: false }, data: [450] }
See updated jsFiddle: http://jsfiddle.net/wergeld/4R5HH/4/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With