php – Highcharts和Mysql

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – Highcharts和Mysql脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我需要这段代码的帮助,我设法从 mysql数据库提取数据并将它们转换为Highcharts所需的格式.

<?PHP
$query =MysqL_query("select
               date_format(connect_time,'%Y-%m-%d %H %i') AS date,Customers.name as customer,Sum(duration) as secondes
               From cdr_Vendors
               inner join Customers on (CDR_Vendors.i_customer = Customers.i_customer)
               where
               i_vendor='32'
               and
               connect_time between '2010-09-01 00:00:00' and '2010-09-01 00:10:00'
               group by date
               ORDER BY date",$link) or die(MysqL_error());
$row = MysqL_fetch_assoc($query);
$customer[] = $row['customer'];
$json_secondes = array();
$json_date = array();
do{
$secondes[] = $row['secondes'];
array_push($json_secondes,$row['secondes']);
array_push($json_date,$row['date']);
}
while($row = MysqL_fetch_assoc($query));
//echo json_encode($json_secondes,$row);
//echo json_encode($json_date,$row);
//echo join($secondes,',');
?>
<htML>
   <head>
      <Meta http-equiv="Content-tyPE" content="text/html; charset=utf-8">
      <tITle>Highcharts Example</title>


      <!-- 1. Add these JavaScript inclusions in the head of your page -->
      <script type="text/javascript" src="http://ajax.GOOGLEapis.COM/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
      <script type="text/javascript" src="../js/highcharts.js"></script>

      <!-- 1a) Optional: the exporting module -->
      <script type="text/javascript" src="../js/modules/exporting.js"></script>


      <!-- 2. Add the JavaScript to initialize the chart on document ready -->
      <script type="text/javascript">

         VAR chart;
         $(document).ready(function() {
            chart = new Highcharts.Chart({
               chart: {
                  renderTo: 'container',defaultseriesType: 'column'
               },title: {
                  text: 'Monthly Average Rainfall'
               },suBTitle: {
                  text: 'Source: WorldCliMATE.com'
               },xAxis: {
                  categories: <?PHP echo json_encode($json_date,$row);?>
               },yAxis: {
                  min: 0,title: {
                     text: 'Rainfall (mm)'
                  }
               },legend: {
                  layout: 'vertical',backgroundColor: '#FFFFFF',align: 'center',verticalAlign: 'top',x: 100,y: 70
               },tooltip: {
                  formatter: function() {
                     return ''+
                        this.x +': '+ this.y +' Min';
                  }
               },plotOptions: {
                  column: {
                     pointPadding: 0.2,borderWidth: 0
                  }
               },series: [{
                  name: '<?PHP echo join($customer,');?>',data: [<?PHP echo join($secondes,');?>]

               }]
            });


         });

      </script>

   </head>
   <body>

      <!-- 3. Add the container -->
      <div id="container" style="width: 1300px; height: 500px; margin: 0 auto"></div>


   </body>
</html>

代码的问题在于它仅显示来自单个客户的数据,因此查询返回来自多个客户的数据.

这种方法是好的还是有另一种更简单方法呢?

解决方法

尝试使用implode(‘,’,$customer);和implode(‘,$secondes);而不是连接功能.

脚本宝典总结

以上是脚本宝典为你收集整理的php – Highcharts和Mysql全部内容,希望文章能够帮你解决php – Highcharts和Mysql所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。