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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?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

1
2
3
4
5
6
7
8
9
<?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' );
?>


数据库:

1
2
3
4
5
6
7
8
9
10
11
12
13
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     |                |
+ --------+-------------+------+-----+---------+----------------+
rows  in  set  (0.00 sec)
1
2
3
4
5
6
7
8
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     |                |
+ --------+-------------+------+-----+---------+----------------+
rows  in  set  (0.00 sec)

wKioL1kSgEHjzaQvAABCXzUC5to916.png-wh_50








      本文转自谢育政 51CTO博客,原文链接:http://blog.51cto.com/kurolz/1923809,如需转载请自行联系原作者



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值