從數(shù)據(jù)庫(kù)中取出最近三十天的數(shù)據(jù)并生成柱狀圖
更新時(shí)間:2011年05月07日 23:52:52 作者:
從數(shù)據(jù)庫(kù)中取出最近三十天的數(shù)據(jù)并生成柱狀圖的代碼,需要的朋友可以參考下。
在終端用cd 命令進(jìn)入文件目錄
說(shuō)明:此處例子我是拿項(xiàng)目中的一個(gè)例子講解的。
1、新建一個(gè)項(xiàng)目 :用終端輸入:zf create project Airline 格式:zf create action project project-name 備注:這些格式可以在終端輸入zf 查看
2、新建一個(gè)action :zf create action dirgramshow index 格式:zf create action action-name controller-name
3、新建一個(gè) model :zf create db-table flightinformation
action 層代碼:indexController.php
public function indexAction ()
{
// action body
$db = new Application_Model_DbTable_Flightinformation();
/*獲取最近30天內(nèi)的數(shù)目
* 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)<=date(boo_time)
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)<=date(boo_time) " .
"group by DATE_FORMAT(boo_time,'%m %d')";
$result = $db->getAllInfo($sql)->fetchAll();
$this->view->result=$result;
}
view 層代碼:dirgramshow.phtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>航班折線圖</title>
<script language="javascript" type="text/javascript"
src="<?php
echo $this->baseUrl() . '/skin/source/jquery/jquery.js'?>"></script>
<script language="javascript" type="text/javascript"
src="<?php
echo $this->baseUrl() . '/skin/js/ZJPjscharts.js'?>"></script>
</head>
<body>
<div id="graph">Loading graph...</div>
<script type="text/javascript">
var d=new Array();
var color=new Array();
<?php
foreach ($this->result as $key => $value) {
?>
d.push(new Array('<?php
echo $value['day']?>',<?php
echo $value['count']?>));
color.push('#2D6B96');
<?php
}
?>
if(d!=""){
//['#2D6B96', '#327AAD', '#3E90C9', '#55A7E3', '#60B6F0', '#81C4F0', '#9CCEF0']
var myData = d;
var colors =color;
var myChart = new JSChart('graph', 'bar');
myChart.setDataArray(myData);
myChart.colorizeBars(colors);
myChart.setTitle('Airline diagram');
myChart.setTitleColor('#8E8E8E');
myChart.setAxisNameX('');
myChart.setAxisNameY('');
myChart.setAxisColor('#C4C4C4');
myChart.setAxisNameFontSize(16);
myChart.setAxisNameColor('#999');
myChart.setAxisValuesColor('#777');
myChart.setAxisColor('#B5B5B5');
myChart.setAxisWidth(1);
myChart.setBarValuesColor('#2F6D99');
myChart.setBarOpacity(0.5);
myChart.setAxisPaddingTop(60);
myChart.setAxisPaddingBottom(40);
myChart.setAxisPaddingLeft(45);
myChart.setTitleFontSize(11);
myChart.setBarBorderWidth(0);
myChart.setBarSpacingRatio(50);
myChart.setBarOpacity(0.9);
myChart.setFlagRadius(6);
myChart.setTooltip(['North America', 'U.S.A and Canada']);
myChart.setTooltipPosition('nw');
myChart.setTooltipOffset(3);
myChart.setSize(616, 321);
/*myChart.setBackgroundImage('<?php
//echo $this->baseUrl() . '/skin/image/ZJPchart_bg.jpg'?>');*/
myChart.draw();
}
</script>
</body>
</html>
model 層代碼:Flightinformation.php
<?php
class Application_Model_DbTable_Flightinformation extends Zend_Db_Table_Abstract
{
protected $_name = 'flightinformation';
public function getAllInfo($sql){
$adapter = Zend_Registry::get('db');
$flightinformation = $adapter->query($sql);
return $flightinformation;
}
}
說(shuō)明:此處例子我是拿項(xiàng)目中的一個(gè)例子講解的。
1、新建一個(gè)項(xiàng)目 :用終端輸入:zf create project Airline 格式:zf create action project project-name 備注:這些格式可以在終端輸入zf 查看
2、新建一個(gè)action :zf create action dirgramshow index 格式:zf create action action-name controller-name
3、新建一個(gè) model :zf create db-table flightinformation
action 層代碼:indexController.php
復(fù)制代碼 代碼如下:
public function indexAction ()
{
// action body
$db = new Application_Model_DbTable_Flightinformation();
/*獲取最近30天內(nèi)的數(shù)目
* 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)<=date(boo_time)
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)<=date(boo_time) " .
"group by DATE_FORMAT(boo_time,'%m %d')";
$result = $db->getAllInfo($sql)->fetchAll();
$this->view->result=$result;
}
view 層代碼:dirgramshow.phtml
復(fù)制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>航班折線圖</title>
<script language="javascript" type="text/javascript"
src="<?php
echo $this->baseUrl() . '/skin/source/jquery/jquery.js'?>"></script>
<script language="javascript" type="text/javascript"
src="<?php
echo $this->baseUrl() . '/skin/js/ZJPjscharts.js'?>"></script>
</head>
<body>
<div id="graph">Loading graph...</div>
<script type="text/javascript">
var d=new Array();
var color=new Array();
<?php
foreach ($this->result as $key => $value) {
?>
d.push(new Array('<?php
echo $value['day']?>',<?php
echo $value['count']?>));
color.push('#2D6B96');
<?php
}
?>
if(d!=""){
//['#2D6B96', '#327AAD', '#3E90C9', '#55A7E3', '#60B6F0', '#81C4F0', '#9CCEF0']
var myData = d;
var colors =color;
var myChart = new JSChart('graph', 'bar');
myChart.setDataArray(myData);
myChart.colorizeBars(colors);
myChart.setTitle('Airline diagram');
myChart.setTitleColor('#8E8E8E');
myChart.setAxisNameX('');
myChart.setAxisNameY('');
myChart.setAxisColor('#C4C4C4');
myChart.setAxisNameFontSize(16);
myChart.setAxisNameColor('#999');
myChart.setAxisValuesColor('#777');
myChart.setAxisColor('#B5B5B5');
myChart.setAxisWidth(1);
myChart.setBarValuesColor('#2F6D99');
myChart.setBarOpacity(0.5);
myChart.setAxisPaddingTop(60);
myChart.setAxisPaddingBottom(40);
myChart.setAxisPaddingLeft(45);
myChart.setTitleFontSize(11);
myChart.setBarBorderWidth(0);
myChart.setBarSpacingRatio(50);
myChart.setBarOpacity(0.9);
myChart.setFlagRadius(6);
myChart.setTooltip(['North America', 'U.S.A and Canada']);
myChart.setTooltipPosition('nw');
myChart.setTooltipOffset(3);
myChart.setSize(616, 321);
/*myChart.setBackgroundImage('<?php
//echo $this->baseUrl() . '/skin/image/ZJPchart_bg.jpg'?>');*/
myChart.draw();
}
</script>
</body>
</html>
model 層代碼:Flightinformation.php
復(fù)制代碼 代碼如下:
<?php
class Application_Model_DbTable_Flightinformation extends Zend_Db_Table_Abstract
{
protected $_name = 'flightinformation';
public function getAllInfo($sql){
$adapter = Zend_Registry::get('db');
$flightinformation = $adapter->query($sql);
return $flightinformation;
}
}
最后的效果圖如下:
您可能感興趣的文章:
- JavaScript可視化圖表庫(kù)D3.js API中文參考
- D3.js中data(), enter() 和 exit()的問(wèn)題詳解
- D3.js 從P元素的創(chuàng)建開始(顯示可加載數(shù)據(jù))
- 基于d3.js實(shí)現(xiàn)實(shí)時(shí)刷新的折線圖
- Javascript實(shí)時(shí)柱狀圖實(shí)現(xiàn)代碼
- JavaScript根據(jù)數(shù)據(jù)生成百分比圖和柱狀圖的實(shí)例代碼
- jQuery.Highcharts.js繪制柱狀圖餅狀圖曲線圖
- PHP 柱狀圖實(shí)現(xiàn)代碼
- php報(bào)表之jpgraph柱狀圖實(shí)例代碼
- D3.js實(shí)現(xiàn)柱狀圖的方法詳解
相關(guān)文章
Mysql中varchar長(zhǎng)度設(shè)置方法
這篇文章主要介紹了Mysql中varchar長(zhǎng)度設(shè)置方法的相關(guān)資料,本文還給大家?guī)?lái)了valar類型的變化及char()和varchar()的區(qū)別介紹,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-07-07MySQL 5.6 (Win7 64位)下載、安裝與配置圖文教程
這篇文章主要介紹了MySQL 5.6 (Win7 64位)下載、安裝與配置圖文教程的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-07-07給Mysql添加遠(yuǎn)程訪問(wèn)權(quán)限的方法
這篇文章主要介紹了給Mysql添加遠(yuǎn)程訪問(wèn)權(quán)限的方法的相關(guān)資料,需要的朋友可以參考下2015-03-03關(guān)于MyBatis連接MySql8.0版本的配置問(wèn)題
這篇文章主要介紹了關(guān)于MyBatis連接MySql8.0版本的配置問(wèn)題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-12-12MySQL之解決字符串?dāng)?shù)字的排序失效問(wèn)題
這篇文章主要介紹了MySQL之解決字符串?dāng)?shù)字的排序失效問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-08-08mysql 數(shù)據(jù)庫(kù)取前后幾秒 幾分鐘 幾小時(shí) 幾天的語(yǔ)句
這篇文章主要介紹了mysql 數(shù)據(jù)庫(kù)中取前后幾秒 幾分鐘 幾小時(shí) 幾天的語(yǔ)句,需要的朋友可以參考下2018-01-01MySQL觸發(fā)器的使用和優(yōu)缺點(diǎn)介紹
大家好,本篇文章主要講的是MySQL觸發(fā)器的使用和優(yōu)缺點(diǎn)介紹,感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話記得收藏一下哦,方便下次瀏覽2021-12-12