当前位置: 编程技术>php
php+highchats生成动态统计图
来源: 互联网 发布时间:2014-08-26
本文导语: 代码如下: series: [{ type: 'pie', name: 'Browser share', data: [ ['Firefox', 45.0], ['IE', ...
代码如下:
series: [{
type: 'pie',
name: 'Browser share',
data: [
['Firefox', 45.0],
['IE', 26.8],
{
name: 'Chrome',
y: 12.8,
sliced: true,
selected: true
},
['Safari', 8.5],
['Opera', 6.2],
['Others', 0.7]
]
}]
主要看这段:
代码如下:
{
name: 'Chrome',
y: 12.8,
sliced: true,
selected: true
}
代码如下:
FusionCharts
$(function () {
var ds = [{"name":"u4e0au6d77","y":28.2},{"name":"u5317u4eac","y":48.2},{"name":"u5e7fu4e1c","y":18.2}];
//其实只要按照例子中的json显示方式展示就行了,如chrome。
// Radialize the colors
Highcharts.getOptions().colors = Highcharts.map(Highcharts.getOptions().colors, function(color) {
return {
radialGradient: { cx: 0.5, cy: 0.3, r: 0.7 },
stops: [
[0, color],
[1, Highcharts.Color(color).brighten(-0.3).get('rgb')] // darken
]
};
});
// Build the chart
$('#container').highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'Browser market shares at a specific website, 2010'
},
tooltip: {
pointFormat: '{series.name}: {point.percentage:.1f}%'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
formatter: function() {
return ''+ this.point.name +': '+ this.percentage +' %';
}
}
}
},
series: [{
type: 'pie',
name: 'Browser share',
data: ds,
}]
});
});
以下是php输出json数据,供js使用:
代码如下:
输出:
代码如下:
{"2":{"name":"lo","data":[0,0]},"3":{"name":"eth0","data":[0.40377,0.00353]}}
js调用:
代码如下:
series: [
ds[2], ds[3]
]