use db_student; mysql> desc stu_inf; +--------+-------------+------+-----+---------+..."/>
溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

PHP +jpgraph實現(xiàn)柱型圖表,但是橫坐標(biāo)顯示為框框,不知是何原因

發(fā)布時間:2020-06-04 08:23:35 來源:網(wǎng)絡(luò) 閱讀:713 作者:謝育政 欄目:web開發(fā)
<?php
header('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","全校學(xué)生數(shù)量"));
$graph->xaxis->title->Set(iconv("utf-8","gb2312","學(xué)院"));
$graph->xaxis->SetTickLabels($xy);
$graph->yaxis->title->Set(iconv("utf-8","gb2312",'人數(shù)'));
$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();
?>


數(shù)據(jù)庫連接:conn.php

<?php
define('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("連接數(shù)據(jù)庫服務(wù)器失敗!".mysqli_connect_err
or());
mysqli_query($conn,'set names utf8');
?>


數(shù)據(jù)庫:

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)

PHP +jpgraph實現(xiàn)柱型圖表,但是橫坐標(biāo)顯示為框框,不知是何原因

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI