PHP +jpgraph實現柱型圖表

來源:互聯網
上載者:User

標籤:php   jpgraph   柱型圖表   

<?phpheader(‘connect-type:text/html; charset=utf-8‘);include ‘conn.php‘;$sql = "select xy_id,count(1) as counts from stu_inf group by xy_id";$r = $conn -> query($sql);$rs = array();while ($row = mysqli_fetch_array($r)){    $rs[] = $row[‘counts‘];}$sql_xy = "select * from xy_inf group by xy_id";$r_xy = $conn -> query($sql_xy);$xy = array();while ($row_xy = mysqli_fetch_array($r_xy)){    $xy[] = $row_xy[‘stu_xy‘];}require_once ‘src/jpgraph.php‘;require_once ‘src/jpgraph_bar.php‘;$graph = new Graph(600, 300);$graph->SetScale(‘textlin‘);$graph->SetShadow();                                                                                                         $graph->img->SetMargin(40, 30, 20, 40);$barplot = new BarPlot($rs);$graph->Add($barplot);$barplot->value->Show();$graph->title->Set(iconv("utf-8","gb2312","全校學生數量"));$graph->xaxis->title->Set(iconv("utf-8","gb2312","學院"));$graph->xaxis->SetTickLabels($xy);$graph->yaxis->title->Set(iconv("utf-8","gb2312",‘人數‘));$graph->title->SetFont(FF_SIMSUN, FS_BOLD);$graph->xaxis->title->SetFont(FF_SIMSUN,FS_BOLD);$graph->yaxis->title->SetFont(FF_SIMSUN,FS_BOLD);$graph->Stroke();?>


資料庫連接:conn.php

<?phpdefine(‘DB_HOST‘, ‘localhost‘);define(‘DB_USER‘, ‘root‘);define(‘DB_PASSWORD‘, ‘‘);define(‘DB_DATABASE‘,‘db_student‘);$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD,DB_DATABASE) or die("串連資料庫伺服器失敗!".mysqli_connect_error());mysqli_query($conn,‘set names utf8‘);?>


資料庫:

mysql> use db_student;mysql> desc stu_inf;+--------+-------------+------+-----+---------+----------------+| Field  | Type        | Null | Key | Default | Extra          |+--------+-------------+------+-----+---------+----------------+| id     | smallint(6) | NO   | PRI | NULL    | auto_increment || stu_xh | varchar(8)  | NO   | UNI | NULL    |                || stu_xm | varchar(40) | NO   |     | NULL    |                || xb_id  | smallint(6) | NO   | MUL | NULL    |                || xy_id  | smallint(6) | NO   |     | NULL    |                || stu_bj | varchar(4)  | NO   |     | NULL    |                |+--------+-------------+------+-----+---------+----------------+6 rows in set (0.00 sec)
mysql> desc xy_inf;+--------+-------------+------+-----+---------+----------------+| Field  | Type        | Null | Key | Default | Extra          |+--------+-------------+------+-----+---------+----------------+| xy_id  | smallint(6) | NO   | PRI | NULL    | auto_increment || stu_xy | varchar(40) | NO   |     | NULL    |                |+--------+-------------+------+-----+---------+----------------+2 rows in set (0.00 sec)


本文出自 “Kurol.Blog” 部落格,請務必保留此出處http://kurol.blog.51cto.com/11433546/1923809

PHP +jpgraph實現柱型圖表

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.