updating a series to have less categories than previously - Javascript highcharts

Javascript examples for highcharts:Chart Configuration

Description

updating a series to have less categories than previously

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="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
      <script type="text/javascript">
    $(window).load(function(){/* ww  w. j  av  a  2 s.co m*/
$(function() {
    var chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            type: 'column'
        },
        xAxis: {
            categories: ['pizza', 'french fries']
        },
        series: [{
            data: [55, 32]
        }]
    });
    $('#update1').toggle(function() {
        chart.series[0].setData([55, 32, 17], false);
        chart.xAxis[0].setCategories(['pizza', 'french fries', 'nachos'], false);
        chart.redraw();
        $(this).text('now, click again to switch back to 2 columns');
    }, function () {
        try {
            chart.series[0].remove();
            chart.addSeries({});
            chart.series[0].setData([55, 32], false);
            chart.xAxis[0].setCategories(['pizza', 'french fries'], false);
            chart.redraw();
        } catch (e) {
            console.log(e);
        }
        $(this).text('update series, adding a new row');
    });
});
    });

      </script> 
   </head> 
   <body> 
      <script src="https://code.highcharts.com/highcharts.src.js"></script> 
      <div id="container" style="height: 400px"></div> 
      <button id="update1">update series, adding a new row</button>  
   </body>
</html>

Related Tutorials