以前用PHP作图时必须要掌握复杂抽象的画图函数,或者借助一些网上下载的花柱形图、饼形图的类来实现。没有一个统一的chart类来实现图表的快速开发。
JpGraph就是解决这个问题的一个不错的类库。
jpgraph的官网
http://www.aditus.nu/jpgraph/
最新版本:支持PHP4的v1.21b、支持PHP5的v2.2。
让php jpgraph支持中文的例子
PHP:注意,如果使用的是linux服务器,如果没有安装truetype字体,则需要上传相关的字体到linux的/usr/X11R6/lib/X11/fonts/truetype目录,上面的例子就需要传
<?php
include ("./graph/jpgraph.php");
include ("./graph/jpgraph_bar.php");
// Some data
$databary=array(152,7,16,5,7,14,9,3);
$databarx= array("中文","德文", 'hi', 'd','dddd','a','b','e') ;
// New graph with a drop shadow
$graph = new Graph(300,200,'auto');
//$graph->SetShadow();
// Use a "text" X-scale
$graph->SetScale("textlin");
/**
* X坐标的内容
*/
$graph->xaxis->SetTickLabels($databarx);
//$graph->xaxis->SetTextLabelInterval(3);
$graph->xaxis->SetFont(FF_SIMSUN,FS_NORMAL);
// Set title and subtitle
$graph->title->Set("测试数据");
// Use built in font
/**
* 使用中文字体支持中文的显示
*/
$graph->title->SetFont(FF_SIMSUN,FS_BOLD,14);
// create the bar plot
$b1 = new BarPlot($databary);
/**
* 这个是 图例
*/
$b1->SetLegend("Temperature");
/**
* 这个是 柱状的宽度
*/
$b1->SetAbsWidth(6);
/**
* 这个是 柱状的投影, 不要
*/
//$b1->SetShadow();
// The order the plots are added determines who's ontop
$graph->Add($b1);
// Finally output the image
$graph->Stroke();
?>
/usr/X11R6/lib/X11/fonts/truetype/simhei.ttf
/usr/X11R6/lib/X11/fonts/truetype/simsun.ttc
