Dynamically add series value to category name - Javascript highcharts

Javascript examples for highcharts:Chart Series

Description

Dynamically add series value to category name

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Highcharts Demo</title> 
      <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> 
      <script type="text/javascript">
$(function() {//from  www  . ja  v  a  2  s .  c  om
  var chart;
  $(document).ready(function() {
    $("#updateAxis").click(function() {
      for (var i = 0; i < chart.series.length; i++) {
        chart.series[i].addPoint({
          y: Math.random() * 5,
          name: 'Bananas' // new category name
        }, true, true);
      }
    });
    chart = new Highcharts.Chart({
      chart: {
        renderTo: 'container',
        type: 'bar'
      },
      title: {
        text: 'Stacked bar chart'
      },
      xAxis: {
        type: 'category'
      },
      yAxis: {
        min: 0,
        title: {
          text: 'Total fruit consumption'
        }
      },
      legend: {
        backgroundColor: '#FFFFFF',
        reversed: true
      },
      tooltip: {
        formatter: function() {
          return '' +
            this.series.name + ': ' + this.y + '';
        }
      },
      plotOptions: {
        series: {
          stacking: 'normal'
        }
      },
      series: [{
        name: 'John',
        data: [{
          y: 5,
          name: 'Apples'
        }, {
          y: 2,
          name: 'Oranges'
        }, {
          y: 3,
          name: 'Pears'
        }]
      }, {
        name: 'Jane',
        data: [{
          y: 2,
          name: 'Apples'
        }, {
          y: 4,
          name: 'Oranges'
        }, {
          y: 2,
          name: 'Pears'
        }]
      }, {
        name: 'Joe',
        data: [{
          y: 3,
          name: 'Apples'
        }, {
          y: 5,
          name: 'Oranges'
        }, {
          y: 1,
          name: 'Pears'
        }]
      }]
    });
  });
});

      </script> 
   </head> 
   <body> 
      <script src="https://code.highcharts.com/highcharts.js"></script> 
      <button id="updateAxis">Update Axis</button> 
      <div id="container" style="height: 400px"></div>  
   </body>
</html>

Related Tutorials