php+highchats生成动态统计图
2015-01-24信息快讯网
这篇文章主要介绍了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
}
<!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" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
<?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 style="white-space:pre"> </span>ds[2], ds[3]
<span style="white-space:pre"> </span>]
php的ZipArchive类用法实例
PHP启动windows应用程序、执行bat批处理、执行cmd命令的方法(exec、system函数详解)
php生成xml时添加CDATA标签的方法
PHP @ at 记号的作用示例介绍
在Win7 中为php扩展配置Xcache
PHP的switch判断语句的“高级”用法详解
PHP中echo,print_r与var_dump区别分析
PHP错误Warning: Cannot modify header information - headers already sent by解决方法
PHP中file_get_contents高用法实例
PHP实现支持GET,POST,Multipart/form-data的HTTP请求类
安装ImageMagick出现error while loading shared libraries的解决方法
php实现的click captcha点击验证码类实例
php实现的Captcha验证码类实例
YII中assets的使用示例
PHP错误Allowed memory size of 67108864 bytes exhausted的3种解决办法
PHP中file_exists函数不支持中文名的解决方法
ThinkPHP行为扩展Behavior应用实例详解
PHP+memcache实现消息队列案例分享
PhpDocumentor 2安装以及生成API文档的方法
PHP中date与gmdate的区别及默认时区设置
codeigniter框架The URI you submitted has disallowed characters错误解决方法
JS异常处理try..catch语句的作用和实例
php加速器eAccelerator的配置参数、API详解
PHP FATAL ERROR: CALL TO UNDEFINED FUNCTION BCMUL()解决办法
Fatal error: session_start(): Failed to initialize storage module: files问题解决方法
PHP的preg_match匹配字符串长度问题解决方法
php数组查找函数in_array()、array_search()、array_key_exists()使用实例
php中有关字符串的4个函数substr、strrchr、strstr、ereg介绍和使用例子
CodeIgniter框架提示Disallowed Key Characters的解决办法
用PHP和Shell写Hadoop的MapReduce程序
PHP fopen()和 file_get_contents()应用与差异介绍
PHP的password_hash()使用实例
PHP中is_file不能替代file_exists的理由
php的hash算法介绍
分享下页面关键字抓取components.arrow.com站点代码
解决file_get_contents无法请求https连接的方法