<?php
header ( "Content-type: text/html; charset=UTF-8" ); //设置文件编码格式
include ("jpgraph/jpgraph.php");
include ("jpgraph/jpgraph_line.php");
$conn = mysql_connect('localhost','root','') or die('数据库连接失败');
mysql_select_db('db_test9') or die('数据库不存在');
mysql_query('set names utf8');
$sql = 'select a.xm,b.cj from tb_stuinf a, tb_grade b where km="数学" and a.xh=b.xh';
$r = mysql_query($sql);
$x = array();
$y = array();
while($row = mysql_fetch_array($r)){
$x[] = iconv("utf-8","gb2312",$row['xm']);
$y[] = $row['cj'];
}
$graph = new Graph(450,275); //创建图像
$graph->SetMargin(40,40,40,50); //设置图像的边框
$graph->SetScale("textint"); //定义刻度值的类型
$graph->SetShadow(); //设置图像阴影
$graph->title->Set(iconv("utf-8","gb2312",'数学成绩')); //定义标题
$graph->title->SetFont(FF_SIMSUN, FS_BOLD); //设置标题字
$graph->title->SetMargin(10); //设置标题字
$graph->xaxis->SetTickLabels($x);
$graph->xaxis->SetFont(FF_SIMSUN, FS_BOLD,8); //定义字体
$graph->xaxis->title->Set(iconv("utf-8","gb2312",'学号')); //设置X轴的标题
$graph->xaxis->title->SetFont(FF_SIMSUN, FS_BOLD); //设置标题字
$graph->xaxis->title->SetMargin(10); //定义字体
$p1 = new LinePlot($y); //创建折线图像
$p1->value->SetFont(FF_ARIAL,FS_BOLD); //定义图像值的字体
$graph->Add($p1);
$p1->value->Show(); //输出图像对应的数据值
$graph->Stroke(); //输出图像
?>
php JbGraph
最新推荐文章于 2024-04-18 00:05:55 发布