Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can do it in several ways</p> <p>Highchart has a very cool <a href="http://api.highcharts.com/highstock#object-Renderer" rel="nofollow">renderer</a> that allows you to add various graphics to the chart. One of the options is to add a <a href="http://www.w3schools.com/svg/svg_path.asp" rel="nofollow">path</a> I will be illustrating the same here.</p> <p>We shall reuse the path of the crosshair and add the same to the chart with some additional styles like color you mentioned. The path of the crosshair can be optained as <code>this.tooltip.crosshairs[0].d</code> this is in string form and can be easily converted to an array using the <code>Array.split()</code> function</p> <pre><code>click: function() { this.renderer.path(this.tooltip.crosshairs[0].d.split(" ")).attr({ 'stroke-width': 2, stroke: 'red' }).add(); } </code></pre> <p>This will accomplish adding the line. You can store the returned object into a global variable and then when you are about to add another such line, you can destroy the existing one by calling <a href="http://api.highcharts.com/highstock#Element.destroy%28%29" rel="nofollow"><code>Element.destroy()</code></a></p> <pre><code> var line; ... chart:{ events: { click: function() { if (line) { line.destroy(); } line = this.renderer.path(this.tooltip.crosshairs[0].d.split(" ")).attr({ 'stroke-width': 2, stroke: 'red' }).add(); } } ... </code></pre> <p><a href="http://jsfiddle.net/jugal/Jee8R/" rel="nofollow">Persist tooltip / crosshair on click @ jsFiddle</a></p> <p>Assuming you don't have much meta data to be shown along with the line, this is the easiest (or the coolest :) ) approach. You can also attach meta data if you want to using the renderer's text object etc.</p> <p>An alternate way could be <a href="http://api.highcharts.com/highstock#Axis.addPlotLine%28%29" rel="nofollow">adding vertical plotLines to the xAxis</a></p> <h1>UPDATE</h1> <p>Refer my other solution to this question, that would work with zoom,scroll,etc</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload