Reposition the dataPoint by select and drag - CanvasJS HTML-JavaScript chart

Reposition the dataPoint by select and drag - CanvasJS HTML-JavaScript chart

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>

CSS

.canvasjs-chart-toolbar {
  display: none !important;
}

JavaScript

var chart = new CanvasJS.Chart("chartContainer",
	{
  		title:{
      	text:"Reposition the dataPoint by select and drag"
      },
  	  zoomEnabled: true,
      zoomType:"xy",
      rangeChanging: getViewport, //We are usig rangeChanging for knowing new y value after dragging
      data: [
        {
          type: "line",
          mouseover: mouseoverHandler,
          mouseout: mouseoutHandler,
          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}
          ]
        },
         {
            //It's a dummy invisible dataseries only for the purpose of increasing x or y value even upto samll values
            toolTipContent:null,
            color:"transparent",
            dataPoints:[{x:.1, y:.1},{x:.2, y:.2}]
         }
      ]
    });

chart.render();
 
document.getElementById("chartContainer").onmousedown = function(){
      chart.isMouseDown = true;
 };
   
function mouseoutHandler(e){
	if(!e.chart.isMouseDown)
  	 e.chart.draggingDataPoint = null;
}
   
 function mouseoverHandler(e){
    e.chart.draggingDataPoint = e.dataPoint;
 }


 //Function for getting viewport and set corrosponding x and y value
function getViewport(e){

    if(e.chart.isMouseDown && e.chart.draggingDataPoint){
      //For updating the y value
	 	 e.chart.draggingDataPoint.x = (e.axisX[0].viewportMaximum-e.chart.draggingDataPoint.x) >
                                       (e.chart.draggingDataPoint.x - e.axisX[0].viewportMinimum) ?
                                        e.axisX[0].viewportMaximum :  e.axisX[0].viewportMinimum;
         e.chart.draggingDataPoint.y = (e.axisY[0].viewportMaximum-e.chart.draggingDataPoint.y) >
                                       (e.chart.draggingDataPoint.y - e.axisY[0].viewportMinimum) ?
                                       ...