温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

PHP +jpgraph实现柱型图表,但是横坐标显示为框框,不知是何原因

发布时间:2020-06-04 08:23:35 来源:网络 阅读:713 作者:谢育政 栏目:web开发
<?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","全校学生数量"));
$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

<?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("连接数据库服务器失败!".mysqli_connect_err
or());
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)

PHP +jpgraph实现柱型图表,但是横坐标显示为框框,不知是何原因

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI