highcharts php mysql_php – Highcharts和Mysql

我需要这段代码的帮助,我设法从

mysql数据库中提取数据并将它们转换为Highcharts所需的格式.

$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, ', ');

?>

Highcharts Example

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, ', ');?>]

}]

});

});

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值