首先看看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&#