官方下载地址:jpgraph.net
最近项目要做个统计,需要用到图表来显示;php对图报表支持不是很好,只好用提供的其他包来解决了,jpgraph的展现还不错,不过比起c#的图像UI似乎还差不少。
下载后的jpgraph里面的example里面有不少的例子,基本上可以找到对应的;
有一点是要特别说明的,在中文显示的时候可能会有点问题,解决如下:
1:首先你创建的php文件需要是utf-8编码的,对于MVC模板的,模板文件编码不做要求。
2:jpgraph/jpgraph_ttf.inc.php文件的修改如下:
elseif( $aFF === FF_SIMSUN ) {
// Do Chinese conversion
// if( $this->g2312 == null ) {
// include_once 'jpgraph_gb2312.php' ;
// $this->g2312 = new GB2312toUTF8();
// }
// return $this->g2312->gb2utf8($aTxt);
return $aTxt;
}
3:jpgraph/jpgraph_legend.inc.php的修改如下:
//public $font_family=FF_DEFAULT,$font_style=FS_NORMAL,$font_size=8; // old. 12
public $font_family=FF_SIMSUN,$font_style=FS_NORMAL,$font_size=8; // old. 12
4:在输出图像的PHP处理页面如下编码:
$data_x=array('今天','昨天','近7天','近30天');
$graph->xaxis->SetFont(FF_SIMSUN,FS_BOLD);
$graph->xaxis->SetTickLabels($data_x); //设置X轴标记
$graph->yaxis->title->SetFont(FF_SIMSUN,FS_BOLD);
$graph->yaxis->title->Set("注册数量");
$title = '注册会员数量统计';
$graph->title->SetFont(FF_SIMSUN,FS_BOLD);
$graph->title->Set($title);
$graph2->img->SetMargin(60,70,30,70);
$graph2->SetScale("textlin");
$graph2->SetY2Scale('lin',0,100); //百分比
$graph2->y2axis->SetTickSide(SIDE_RIGHT);
$graph2->y2axis->SetColor('black','blue');
$graph2->y2axis->SetLabelFormat('%2d%%');
$graph2->y2axis->title->SetFont(FF_SIMSUN,FS_BOLD);
$graph2->y2axis->title->Set("百分比");
$graph2->legend->SetFrameWeight(1);
$graph2->legend->SetColumns(4);
$graph2->legend->SetColor('#4E4E4E','#00A78A');
在windows下是OK的,但是上传到LINUX服务器就出现了 /usr/share/fonts/truetype/simhei.ttf is not readable or not exists;可以下载simhei.ttf再传入到jpgraph的fonts目录下