delete all of the points from a charts series - Javascript highcharts

Javascript examples for highcharts:Chart Series

Description

delete all of the points from a charts series

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <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> 
   </head> 
   <body> 
      <script src="https://code.highcharts.com/stock/highstock.js"></script> 
      <script src="https://code.highcharts.com/stock/modules/exporting.js"></script> 
      <div id="container" style="height: 500px; min-width: 500px"></div> 
      <input type="button" id="add" value="add"> 
      <input type="button" id="remove" value="remove"> 
      <script type="text/javascript">
$(function() {//from  w w  w .jav  a  2s.c om
var points,
    chart;
    $.getJSON('https://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=?', function(data) {
        points = data;
        // Create the chart
        chart = new Highcharts.StockChart({
            chart : {
                renderTo : 'container'
            },
            rangeSelector : {
                selected : 1
            },
            title : {
                text : 'AAPL Stock Price'
            },
            series : [{
                name : 'AAPL',
                data : points,
                tooltip: {
                    valueDecimals: 2
                }
            }]
        });
    });
    $('#add').click(function() {
        chart.series[0].setData(points);
    });
    $('#remove').click(function() {
        chart.series[0].setData([]);
    });
});

      </script>  
   </body>
</html>

Related Tutorials