Home  >  Article  >  php教程  >  php+highchats生成动态统计图

php+highchats生成动态统计图

WBOY
WBOYOriginal
2016-06-13 09:35:00884browse

复制代码 代码如下:


    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 
             
             
         
         
     
     
   
 
        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); 
    } 
    ?> 
         
     

以下是php输出json数据,供js使用:

复制代码 代码如下:


$strs = @file("/proc/net/dev");  
for ($i = 2; $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  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] 
                     

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn