首先看看echars官网上饼图用法的实例(如下图):
然后来说说这个饼图结合Thinkphp的用法。
思路是这样的:
1.控制器先查询出要的数据包括:legend里data的数据,series里data的数据。
2.把得到的数据处理成json数据,分配到视图。
3.利用分配过来的数据,得到想要的饼图。
具体代码如下:
控制器:
public function index(){
//var_dump($res_es);
$gno = M("auth_group")->count();
$this->assign('gno',$gno);
$uno = M("auth_user")->count();
$this->assign('uno',$uno);
$ino = M("info")->count();
$this->assign('ino',$ino);
$bcno = M("bike_company")->count();
$this->assign('bcno',$bcno);
$uid = $_SESSION['auth']['id'];
//暂时先将超级管理员区别开
if($uid!=1){
//非管理员,根据行政级别进行过滤
//echo "x";
//根据行政级别,做相应的过滤
$province = $_SESSION['auth']['province'];
$city = $_SESSION['auth']['city'];
$area = $_SESSION['auth']['area'];
if($_SESSION['auth']['class']=='省级'){
$sql .= " and province = '$province' ";
$where["province"] = $_SESSION['auth']['province'];
}
if($_SESSION['auth']['class']=='市级'){
$sql .= " and province = '$province' ";
$sql .= " and city = '$city' ";
$where["province"] = $_SESSION['auth']['province'];
$where["city"] = $_SESSION['auth']['city'];
}
if($_SESSION['auth']['class']=='区级'){
$this->assign('ibno',1);
$this->assign('uno',1);
$this->assign('gno',1);
$sql_area_count = "SELECT COUNT(*) as count FROM dwz_info where area = '$area'";
$count = M()->query($sql_area_count);
$this->assign('ino',$count[0]['count']);
$sql .= " and prov

本文介绍了如何结合Echarts饼图组件与Thinkphp框架来展示数据。通过控制器查询所需数据,转化为JSON并传递给视图,最终在前端渲染出饼图。
最低0.47元/天 解锁文章
795

被折叠的 条评论
为什么被折叠?



