从数据库中取出最近三十天的数据并生成柱状图的代码,需要的朋友可以参考下。
在终端用cd 命令进入文件目录
说明:此处例子我是拿项目中的一个例子讲解的。
1、新建一个项目 :用终端输入:zf create project airline 格式:zf create action project project-name 备注:这些格式可以在终端输入zf 查看
2、新建一个action :zf create action dirgramshow index 格式:zf create action action-name controller-name
3、新建一个 model :zf create db-table flightinformation
action 层代码:indexcontroller.php
代码如下:
public function indexaction ()
{
// action body
$db = new application_model_dbtable_flightinformation();
/*获取最近30天内的数目
* select day(boo_time) as day,count(boo_autoid)as count,boo_time from bookinformation
where flag_pass=0 and date_sub(now(), interval 30 day)group by date_format(boo_time,'%m %d')
*/
$sql = select date_format(boo_time,'%m-%d') as day,count(boo_autoid)as count from bookinformation .
where flag_pass=0 and date_sub(now(), interval 30 day)group by date_format(boo_time,'%m %d');
$result = $db->getallinfo($sql)->fetchall();
$this->view->result=$result;
}
view 层代码:dirgramshow.phtml
代码如下:
航班折线图
loading graph...
model 层代码:flightinformation.php
代码如下:
query($sql);
return $flightinformation;
}
}
最后的效果图如下: