程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php+highchats生成動態統計圖實例代碼

php+highchats生成動態統計圖實例代碼

編輯:關於PHP編程

分享下php+highchats生成動態統計圖的方法。

例子: 

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 
}

您可能感興趣的文章:

  • Highcharts教程(22) 柱狀圖例子
  • Highcharts教程(21) 條狀圖例子
  • Highcharts教程(20) 曲線圖例子二
  • Highcharts教程(19) 曲線圖例子一
  • Highcharts教程(18) xAxis x軸樣式二
  • Highcharts教程(17) xAxis x軸的樣式一
  • Highcharts教程(16) tooltip工具提示
  • Highcharts教程(15) title標題、subtitle副標題
  • Highcharts教程(14) Series數據列選項
  • Highcharts教程(13) Pie餅圖與其他圖形
  • Highcharts教程(12) gauge測量圖
  • Highcharts教程(11) bar條狀圖、Column柱狀圖、Columnrange柱狀排列圖
  • Highcharts教程(10) arearange區域排列圖VSareaspline區域曲線圖VSareasplinerangeVSbar條狀圖
  • Highcharts教程(9) PlotOptions之area區域圖
  • Highcharts教程(8) Pane窗格選項、PlotOptions繪圖選項概覽
  • Highcharts教程(7) loading加載選項、navigation 選項
  • Highcharts教程(6) legend 圖例選項
  • Highcharts教程(5) Lang語言選項
  • Highcharts教程(4) global全局選項和labels標簽選項
  • Highcharts教程(3) exporting導出和打印選項
  • Highcharts教程(2) colors顏色與credits名片選項
  • Highcharts教程(1) chart 圖表選項

 

代碼:

<!DOCTYPE HTML> 

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
<title>FusionCharts</title> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> 
<script type="text/javascript"> 
$(function () { 
var ds = [{"name":"\u4e0a\u6d77","y":28.2},{"name":"\u5317\u4eac","y":48.2},{"name":"\u5e7f\u4e1c","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}: <b>{point.percentage:.1f}%</b>' 
}, 
plotOptions: { 
pie: { 
allowPointSelect: true, 
cursor: 'pointer', 
dataLabels: { 
enabled: true, 
color: '#000000', 
connectorColor: '#000000', 
formatter: function() { 
return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %'; 
} 
} 
} 
}, 
series: [{ 
type: 'pie', 
name: 'Browser share', 
data: ds, 
}] 
}); 
}); 
</script> 
</head> 
<body> 
<script src="js/hc.js"></script> 
<script src="js/modules/exporting.js"></script> 
<div id="container">php 
area(); 
/** 
* 地區接口 
* name名稱 
* y數據值 
* 
*/ 
function area() 
{ 
$b = array( 
array('name'=>'上海', 'y'=>28.2), 
array('name'=>'北京', 'y'=>48.2), 
array('name'=>'廣東', 'y'=>18.2), 
); 
$data = json_encode($b); 
echo($data); 
} 
?> 
</body> 
</html> 
以下是php輸出json數據,供js使用:


<?php 
$strs = @file("/proc/net/dev"); 
for ($i = 2; $i < count($strs); $i++ ) 
{ 
preg_match_all( "/([^\s]+):[\s]{0,}(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/", $strs[$i], $info ); 
/* $NetInput[$i] = formatsize($info[2][0]); 
$NetOut[$i] = formatsize($info[10][0]); 
*/ 
$tmo = round($info[2][0]/1024/1024, 5); 
$tmo2 = round($tmo / 1024, 5); 
$NetInput[$i] = $tmo2; 
$tmp = round($info[10][0]/1024/1024, 5); 
$tmp2 = round($tmp / 1024, 5); 
$NetOut[$i] = $tmp2;

}

$arr = array(); 
if (false !== ($strs = @file("/proc/net/dev"))) : 
for ($i = 2; $i < count($strs); $i++ ) : 
preg_match_all( "/([^\s]+):[\s]{0,}(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/", $strs[$i], $info ); 
$arr[$i]["name"] = $info[1][0]; 
$arr[$i]["data"][0] = $NetInput[$i]; 
$arr[$i]["data"][1] = $NetOut[$i];

endfor; 
endif; 
echo(json_encode($arr)); 
?>

輸出:


{"2":{"name":"lo","data":[0,0]},"3":{"name":"eth0","data":[0.40377,0.00353]}}
js調用:

series: [ 
<span>] 
<span > </span>]

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved