thinkphp+jpgraph生成各种统计图

thinkphp+jpgraph生成各种统计图

JpGraph一个强大的php图表类库,它使得作图变成了一件非常简单的事情,你只需从数据库中取出相关数据,定义标题,图表类型,然后的事情就交给JpGraph。

淘建站为您提供更多_PHP功能模块_插件_统计图_图表,在此特别感谢您对我们的支持与厚爱!

加入收藏

下载 151 次

下载资源

49 积分

特别说明:本站资源来自网友发布分享,仅供学习与参考,请勿用于商业用途,若有侵权请联系删除(272966172@qq.com)。
分类:统计图 > 折线图 难易程度:中级

首先我们定义好图表的标题,数据,描述及尺寸。

$dataArr = array(
            array(
                "num" => "20",
                "legend" => "网站模板",
            ),
            array(
                "num" => "30",
                "legend" => "网页特效",
            ),
            array(
                "num" => "40",
                "legend" => "网站源码",
            ),
            array(
                "num" => "15",
                "legend" => "网站psd",
            ),
        );
        $sizesArr = array(
            "width" => "800",
            "height" => "500",
            "size" => "140"
);

接着我们调用jpgraph()函数。第一个参数标题,第二个参数是数据和描述的二维数组,第三个是生成图表的类型,默认折线图。最后是生成图表的尺寸。

$datas = json_encode($dataArr);
$sizes = json_encode($sizesArr);
jpgraph("www.sucaiq.com", $datas, 'line',$sizes);

最后我们看下jpgraph()方法:

function jpgraph($title, $json, $mtype = 'line', $sizeArr) {
    $dates = json_decode($json, true);
    if (empty($sizeArr)) {
        $sizes = array(
            "width" => "800",
            "height" => "500",
            "size" => "140"
        );
    } else {
        $sizes = json_decode($sizeArr, true);
    }

    foreach ($dates as $v) {
        $data[] = $v['num']; //数据
        $legend[] = $v['legend']; //说明
    }
    vendor('Jpgraph.Chart');
    $chart = new \Chart;
    $size = $sizes['size']; //尺寸
    $width = $sizes['width']; //宽度
    $height = $sizes['height']; //高度
    /* 上面的参数各种图都是用,比如:饼图 折线图 柱形图等等,需要改变的就是下面的chart.php中的function的名字 */
    if ($mtype == 'line') { //折线图
        $chart->createmonthline($title, $data, $size, $height, $width, $legend);
    } else if ($mtype == 'column') { //柱状图
        $chart->createcolumnar($title, $data, $size, $height, $width, $legend);
    } else if ($mtype == 'pie') { //饼图
        $chart->create3dpie($title, $data, $size, $height, $width, $legend);
    } else { //圆形统计图
        $chart->createring($title, $data, $size, $height, $width, $legend);
    }
}

声明:本资料由淘建站会员提供,如转载注明来源,资料来源淘建站免费素材库:https://www.taojz.cn/mokuai/163.html
thinkphp+jpgraph生成各种统计图 希望对你有帮助,感谢您的支持!
留言(0)
头像
 阿里云限量代金券,戳我领取
1 2