php – Highcharts和Mysql
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – Highcharts和Mysql,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2436字,纯文字阅读大概需要4分钟。
内容图文
我需要这段代码的帮助,我设法从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所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。
来源:【匿名】