highchart动态添加数据

highchart 动态添加数据
  Highcharts是一个制作图表的纯Javascript类库,支持大部分的图表类型:直线图,曲线图、区域图、区域曲线图、柱状图、饼装图、散布图;使用需要导入jquery.js,highcharts.js以及exporting.js,可以通过网站http://www.highcharts.com/下载!

  由于很多网站的示例是静态数据,在找了很多资料后,整理了一份如何使用动态数据的代码,分享出共供大家使用!
代码如下:
<html> 
  <head> 
    <title>Highcharts Example</title> 
    <script language="javascript" type="text/javascript" src="js/jquery.min.js"></script> 
    <script language="javascript" type="text/javascript" src="js/highcharts.js"></script> 
    <script language="javascript" type="text/javascript" src="js/exporting.js"></script> 
    <script type="text/javascript"> 
      var chart;
      $(document).ready(function() {
        var options = {
          chart: {
            renderTo: 'container',
            type: 'line',
            marginRight: 130,
            marginBottom: 25
          },
          title: {
            text: '每天的分布情况',
            x: -20 //center
          },
          xAxis: {
            categories: ['0', '1', '2', '3','4','5','6','7','8','9']
          },
          yAxis: {
            title: {
              text: 'Y轴'
            },
            plotLines: [{
              value: 0,
              width: 1,
              color: '#808080'
            }]
          },
          tooltip: {
            formatter: function() {
              return '<b>'+ this.series.name +'</b><br/>' + this.x +': '+ this.y ;
            }
          },
          legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'top',
            x: -10,
            y: 100,
            borderWidth: 0
          },
          series: []
        }
        options.series = new Array();
        var i;
        for(i=0;i<10;i++)
        {
           options.series[i] = new Object();
           options.series[i].name = 'Sample'+i;
           options.series[i].data = new Array(0+i, 1+i, 2+i, 3+i,4+i,5+i,6+i,7+i,8+i,9+i);
         }
       chart = new Highcharts.Chart(options);
     });
  </script>
  </head> 
<body> 
   <div id="container" style="width: 800px;height: 400px"></div> 
</body> 
</html> 

你可能感兴趣的:(highchart)