用于调用json数据的Highcharts

时间:2013-09-06 15:47:20

标签: json highcharts

我正在尝试将json数据调用到高级图表。我只有一个系列..新手到这个..任何人都可以帮助我,无论我是否正确调用json文件。请帮忙:(

我的代码在highcharts中调用json

      <script> 
      var chart;
    $(document).ready(function () 
   {
      chart = new Highcharts.Chart({
      chart: {
        renderTo: 'container1',
       type: 'area'
          },
       yAxis: {
    type: 'double',
    min: 0
      },
      xAxis: {
      type: 'datetime',
         labels: {
          formatter: function () {
            return Highcharts.dateFormat('%b %y', this.value);
        },
        dateTimeLabelFormats: {

            month: '%b \'%y',
            year: '%Y'
        }
    }
    },
   series: [{
    name: 'Total Views',
    data: []
    }, ]

  });
 chart.series[0].setData(

  });
  </script>
  <script>    
  $.getJSON('data.php', function(data) 
   {
  chart.series[0].append(data);
     }   

</script>
 <div id="container1" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
 </body>
</html> 

1 个答案:

答案 0 :(得分:1)

您想在getJSON成功函数中创建图表。

 $.getJSON('data.php', function (data) {
      chart = new Highcharts.Chart({
          chart: {
              renderTo: 'container1',
              type: 'area'
          },
          yAxis: {
              type: 'double',
              min: 0
          },
          xAxis: {
              type: 'datetime',
              labels: {
                  formatter: function () {
                      return Highcharts.dateFormat('%b %y', this.value);
                  },
                  dateTimeLabelFormats: {

                      month: '%b \'%y',
                      year: '%Y'
                  }
              }
          },
          series: [{
              name: 'Total Views',
              data: data
          }, ]

      });
  });

这是一个使用JSON和Highcharts http://blueflame-software.com/blog/how-to-load-mysql-results-to-highcharts-using-json/

的简单教程