score:15
You can create an empty series which mimics the characteristics of the plot line (color, dash style...). You can then optionally use the legendItemClick
event to "link it up" to the plot line.
For example, you predefine these variables for ID and plot line options:
plotLineId = 'myPlotLine'; // To identify for removal
// Plot line options for adding
plotLineOptions = {
color: '#FF0000',
id: plotLineId,
width: 2,
value: 5.5,
dashStyle: 'shortdash'
};
Your axis plotline:
xAxis: {
plotLines: [ plotLineOptions ]
}
Your mimic series:
series: [
// ...
{
// Series that mimics the plot line
color: '#FF0000',
name: 'My plotline',
dashStyle: 'shortdash',
marker: {
enabled: false
},
events: {
// Event for showing/hiding plot line
legendItemClick: function(e) {
if(this.visible) {
this.chart.xAxis[0].removePlotLine(plotLineId);
}
else {
this.chart.xAxis[0].addPlotLine(plotLineOptions);
}
}
}
}
]
See this JSFiddle demonstration of how it works (or this minimal example, without events).
score:10
Just as an alternative, if you're going to go so far as to make a fake series that mimics all of the aspects of your plot line...
You can just use that series as your plotLine
, and skip all of the extra work of tying everything together...
like:
{
name: 'Plot Line',
color: 'red',
type:'line',
dashStyle: 'shortdash',
lineWidth: 2,
data: [[minXvalue, plotLineValue], {x:maxXvalue, y:plotLineValue, dataLabels: { enabled: true }}]
}
Example:
Source: stackoverflow.com
Related Query
- How to show plot lines in the legend in Highcharts?
- How to show the legend in HighCharts
- How to hide date time x-axis but still be able to show plot lines in Highcharts gantt chart?
- How to plot horizontal lines over the some columns of columnrange chart in Highcharts
- How to customize a legend in highcharts as the image and while clicking on the leg end appears lines inside linechart
- Highcharts - How to display legend symbol inside the tooltip
- How to Check and Uncheck all the Legend elements in HighCharts Linechart?
- How to adjust the spacing of grid lines in highcharts
- How do I remove the color swatch from my HighCharts legend without affecting the column?
- Highcharts - How do I get dashed lines in legend
- How do I hide a Highcharts series from the chart, but always show it in the tooltip?
- how to display 2 same highcharts without duplicate the code
- How to make legend color show up in Highcharts for a line graph under certain conditions?
- How to keep the highcharts legend "on" while hiding the series
- How to move the legend in Highcharts
- How can I make milestone lines with a GANTT chart using the highcharts library?
- How can I add a text link just below the legend box in highcharts
- Highcharts for multiple plot lines each with a different color and show tooltip?
- Change the legend in highcharts heatmap to show instead of a color bar, a set of fixed icons with hide and show on click
- Highcharts -> how to add vertical title to bar? how to make the symbol in the legend a rectangle?
- Highcharts - How to force dataLabels to show labels when overlapping the content
- Highcharts legend how to show multiple charts data category?
- How do I plot the x axis line using Highcharts when pegged at 0?
- canvg and highcharts how to include chart legend and keep the chart size?
- How to add a vertical plot line in multiple line series and show the tooltip on Plot line in highchart
- How do i color the highcharts legend square symbol when my chart has multiple color entries
- How can i load external json data in highcharts to show the bar chart
- How to show only the last 100 candlesticks or hide the first 50 candlesticks in Highcharts Stock Chart?
- React: How to show correct date and plot data as Months in Highcharts
- Stacked Bar Highcharts how to show the values
More Query from same tag
- put condition depending on the value HIGHCHARTS
- Using chart.update on a chart using renderTo
- Manually set y-axis min and max value and zoom-in behaviour in Highcharts
- Websharper HighCharts Example
- Highcharts Synchronized charts with missing data points
- How to make this chart wider/ enable scrolling?
- Extending highcharts line series to end of chart
- Highcharts Solid Gauge Dynamic Update Using JSON
- HighCharts Solid Gauge Chart not displaying ticks
- Highchart-treemaps equal tiles
- Trying to append arrays to highcharts ( jquery)
- Applying custom color on HighCharts?
- Highcharts Dynamic Drilldown using json
- How to get only whole numbers on the y-axis?
- Overlapping flags in Highstock
- HighChart with large amount of data(complex structure) not working
- ReferenceError: Can't find variable: modules
- Dojo + Highcharts: showAxes property moves the x and y axis
- Highcharts Plot background
- HighCharts: Displaying 3 vu-meters
- Highcharts dataLabel overlap
- Make HTML element fill rest of page
- is supportablerange type graph in Highchart?
- Remove UTC date from Highcharts tooltip
- Take snapshot of HighChart with render.text.css
- Update color of plotline label on change highcharts
- In Highchart legend, Want to bring checkbox at start
- Is possible to set min and max zoom in Time series Highcharts?
- Unable to get value of the property '0': object is null or undefined in IE7
- How to parse the data from CSV FILE to arrays so it could be used for a pre-formatted Highchart