Add data to chart - Javascript highcharts

Javascript examples for highcharts:Chart Data

Description

Add data to chart

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://code.jquery.com/jquery-1.11.0.js"></script> 
      <script type="text/javascript">
    $(window).load(function(){/* w  ww. j  a v a 2s . c o  m*/
$(function () {
    $('#container').highcharts({
            chart: {
                type: 'bar'
            },
            title: {
                text: 'US and USSR nuclear stockpiles'
            },
            subtitle: {
                text: ''
            },
            xAxis: {
                //allowDecimals: false,
                labels: {
                    formatter: function() {
                        return this.value; // clean, unformatted number for year
                    }
                }
            },
            yAxis: {
                title: {
                    text: 'Nuclear weapon states'
                },
                labels: {
                    formatter: function() {
                        return this.value / 1000 +'k';
                    }
                }
            },
            tooltip: {
                pointFormat: '{series.name} produced <b>{point.y:,.0f}</b><br/>warheads in {point.x}'
            },
            plotOptions: {
                bar: {
                    pointStart: 1940,
                    marker: {
                        enabled: false,
                        symbol: 'circle',
                        radius: 2,
                        states: {
                            hover: {
                                enabled: true
                            }
                        }
                    }
                }
            },
            series: [{
                name: 'USA',
                animation:false,
                data: []
            }]
        });
    $('#btn').click(function(){
       var chart = Highcharts.charts[0];
        var val1 = parseFloat($('input[id=m]').val());
        chart.series[0].addPoint(val1);
    });
});
    });

      </script> 
   </head> 
   <body> 
      <input id="m" type="text">
      <button id="btn">add data</button> 
      <script src="https://code.highcharts.com/highcharts.js"></script> 
      <script src="https://code.highcharts.com/highcharts-more.js"></script> 
      <script src="https://code.highcharts.com/modules/exporting.js"></script> 
      <div id="container" style="min-width: 310px; max-width: 800px; height: 400px; margin: 0 auto"> 
      </div>  
   </body>
</html>

Related Tutorials