echarts 饼图 结合thinkphp 的使用

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

首先看看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
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ougexingfuba

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值