时间:2021-07-01 10:21:17 帮助过:3人阅读
主要看这段:
代码如下:
{
name: 'Chrome',
y: 12.8,
sliced: true,
selected: true
}
代码如下:
以下是php输出json数据,供js使用:
代码如下:
$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: [
ds[2], ds[3]
]