php+highchats生成动态统计图

时间:2024-05-02 17:19:08 


    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,highchats
0
投稿

猜你喜欢

  • 最炫Python烟花代码全解析

    2022-02-16 13:07:53
  • python实现批量修改图片格式和尺寸

    2021-02-12 10:47:35
  • python包导入的两种方式

    2022-11-25 22:49:30
  • php中去除所有js,html,css代码

    2023-07-08 07:59:52
  • PHP 进程锁定问题分析研究

    2023-11-21 18:14:10
  • js函数setTimeout延迟执行的简单介绍

    2024-05-05 09:15:14
  • 分享Sql Server 存储过程使用方法

    2024-01-13 06:42:36
  • Python实现大数据收集至excel的思路详解

    2022-02-03 10:25:25
  • Python实现完整的事务操作示例

    2023-11-15 21:02:02
  • python鼠标绘图附代码

    2021-09-09 17:10:26
  • 如何在golang中使用shopspring/decimal来处理精度问题

    2024-05-21 10:24:12
  • python并发场景锁的使用方法

    2022-12-30 17:25:20
  • TIOBE编程语言排行榜前20的语言入门书籍推荐

    2023-04-05 12:19:48
  • 一文带你搞懂Python上下文管理器

    2022-11-26 05:15:50
  • 一文教会你用nginx+uwsgi部署自己的django项目

    2021-04-10 17:57:05
  • Python获取android设备cpu和内存占用情况

    2023-02-25 20:46:47
  • python中多个装饰器的执行顺序详解

    2022-04-30 13:43:51
  • golang中defer的使用规则详解

    2023-07-21 22:47:31
  • 浅谈Python实现opencv之图片色素的数值运算和逻辑运算

    2022-06-11 15:58:50
  • js处理括弧配对替换的方法

    2008-01-16 13:48:00
  • asp之家 网络编程 m.aspxhome.com