Delete Striplines on Double Click - CanvasJS JavaScript Charts

Delete Striplines on Double Click - CanvasJS JavaScript Charts

by canvasjs

HTML

<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<br/><!-- Just so that JSFiddle's Result label doesn't overlap the Chart -->
<div id="chartContainer" style="height: 360px; width: 100%;"></div>

JavaScript

var chart = new CanvasJS.Chart("chartContainer", {
  title: {
    text: "Delete Stripline on Double Cick"
  },
  axisX: {
    stripLines: [{
      startValue: 5,
      endValue: 10
    },{
      startValue: 20,
      endValue: 35
    },{
      startValue: 45,
      endValue: 50
    },{
      startValue: 75,
      endValue: 80
    }]
  },
  data: [
    {
      type: "line",
      dataPoints: [
        { x: 10, y: 71 },
        { x: 20, y: 55 },
        { x: 30, y: 50 },
        { x: 40, y: 65 },
        { x: 50, y: 95 },
        { x: 60, y: 68 },
        { x: 70, y: 28 },
        { x: 80, y: 34 },
        { x: 90, y: 14 }
      ]
    }					
  ]
});

chart.render();

$(".canvasjs-chart-canvas").last().on("dblclick", function(e){
  var stripLineIndex = 0;
  var parentOffset = $(this).parent().offset();
  var relX = e.pageX - parentOffset.left;
  var relY = e.pageY - parentOffset.top;
  for(var i = 0; i < chart.axisX[0].stripLines.length; i++){
    if(relX > chart.axisX[0].stripLines[i].bounds.x1 && relX < chart.axisX[0].stripLines[i].bounds.x2 && relY > chart.axisX[0].stripLines[i].bounds.y1 && relY < chart.axisX[0].stripLines[i].bounds.y2){
      stripLineIndex = i;
    }
  }
  chart.axisX[0].stripLines[stripLineIndex].remove()  
});