Handle series point drag events - Javascript highcharts

Javascript examples for highcharts:Chart Series

Description

Handle series point drag events

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Highcharts Draggable Points</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://code.jquery.com/jquery-1.7.1.js"></script> 
      <style id="compiled-css" type="text/css">

body {//from   w  ww.  j ava  2 s.com
   font-family: Arial, Verdana, sans-serif;
   font-size: 0.8em;
}


      </style> 
      <script type="text/javascript">
    $(function(){
var chart = new Highcharts.Chart({
    chart: {
        renderTo: 'container',
        animation: false
    },
    title: {
        text: 'Highcharts draggable points demo'
    },
    xAxis: {
        categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    },
    plotOptions: {
        series: {
            point: {
                events: {
                    drag: function (e) {
                        // Returning false stops the drag and drops. Example:
                        $('#drag').html(
                            'Dragging <b>' + this.series.name + '</b>, <b>' + this.category + '</b> to <b>' + Highcharts.numberFormat(e.y, 2) + '</b>');
                    },
                    drop: function () {
                        $('#drop').html(
                            'In <b>' + this.series.name + '</b>, <b>' + this.category + '</b> was set to <b>' + Highcharts.numberFormat(this.y, 2) + '</b>');
                    }
                }
            },
            stickyTracking: false
        },
        column: {
            stacking: 'normal'
        },
        line: {
            cursor: 'ns-resize'
        }
    },
    tooltip: {
        yDecimals: 2
    },
    series: [{
        data: [0, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
        //draggableX: true,
        draggableY: true,
        dragMinY: 0,
        type: 'column',
        minPointLength: 2
    }, {
        data: [0, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4].reverse(),
        draggableY: true,
        dragMinY: 0,
        type: 'column',
        minPointLength: 2
    }, {
        data: [0, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
        draggableY: true
    }]
});
    });

      </script> 
   </head> 
   <body> 
      <script src="https://code.highcharts.com/highcharts.js"></script> 
      <script src="https://rawgithub.com/highcharts/draggable-points/master/draggable-points.js"></script> 
      <div id="container" style="height: 400px"></div> 
      <div id="drag"></div> 
      <div id="drop"></div>  
   </body>
</html>

Related Tutorials