Extract data from the database for the last 30 days and generate a bar chart

Source: Internet
Author: User

Run the cd command on the terminal to enter the file directory.
Note: here is an example of the project.
1. create a project: Enter zf create project Airline in the format of zf create action project-name in the terminal. Note: You can enter zf in the terminal to view the format.
2. create an action: zf create action dirgramshow index in the format of zf create action-name controller-name
3. create a model: zf create db-table flightinformation
Code at the action layer: indexController. php Copy codeThe Code is as follows: public function indexAction ()
{
// Action body
$ Db = new Application_Model_DbTable_Flightinformation ();
/* Obtain the number of objects in the last 30 days.
* 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-Layer Code: dirgramshow. phtmlCopy codeThe Code is as follows: <! 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> flight line chart </title>
<Script language = "javascript" type = "text/javascript"
Src = "<? Php
Echo $ this-> baseUrl (). '/skin/source/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 did ');
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 Layer Code: Flightinformation. phpCopy codeThe Code is as follows: <? 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;
}
}

The last one is as follows:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.