plot line and plot click event in area chart - Javascript highcharts

Javascript examples for highcharts:Line Chart

Description

plot line and plot click event in area chart

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Click to highlight bars</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
      <script type="text/javascript">
$(function() {//  w  ww . ja v a2s  . c om
  var myPlotLineId = "myPlotLine";
  var previousPoint = null;
  var updatePoint = function(point) {
      if (previousPoint) {
        previousPoint.update({
          color: '#7cb5ec',
          marker: {
            states: {
              hover: {
                fillColor: '#7cb5ec',
              }
            }
          }
        });
      }
      previousPoint = point;
      point.update({
        color: '#fe5800',
        marker: {
          states: {
            hover: {
              fillColor: '#fe5800',
            }
          }
        }
      });
    },
    addPlotLine = function(evt) {
      var point = evt.point;
      var xValue = point.x;
      var xAxis = point.series.xAxis;
      Highcharts.each(xAxis.plotLinesAndBands, function(p) {
        if (p.id === myPlotLineId) {
          p.destroy();
        }
      });
      xAxis.addPlotLine({
        value: xValue,
        width: 1,
        color: 'red',
        id: myPlotLineId
      });
    };
  $('#container').highcharts({
    chart: {
      type: 'area',
      events: {
        click: function(evt) {
        }
      }
    },
    xAxis: {
      categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    },
    plotOptions: {
      series: {
        point: {
          events: {
            click: function(event) {
              updatePoint(this);
              addPlotLine(event);
            }
          }
        }
      }
    },
    series: [{
      data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
    }]
  });
});

      </script> 
   </head> 
   <body> 
      <script src="https://code.highcharts.com/highcharts.js"></script> 
      <div id="container" style="height: 400px"></div>  
   </body>
</html>

Related Tutorials