jpgraph的使用:
1. 下载jpgraph.tar.zip
2. 解压之后目录如下
---------docportal ;文档说明
---------src ;源代码
目录很简单,进入src文件夹,除example文件夹之外其他的全部拷贝到 ThinkPHP->Library->Vendor->Jpgraph文件夹下。ok
3. 在你的Controller里写如下代码:
public function out(){
$datay=array(0.13,0.25,0.21,0.35,0.31,0.06);
$datax=array("一月份","二月份","三月份","四月份","五","六");
// Setup the graph.
Vendor('Jpgraph.jpgraph');
$graph = new \Graph(900,500);
$graph->img->SetMargin(60,20,35,75);
$graph->SetScale("textlin");
$graph->SetMarginColor("lightblue:1.1");
$graph->SetShadow();
// Set up the title for the graph
$graph->title->Set("简体中文 繁體中文 test");
$graph->title->SetMargin(8);
$graph->title->SetFont(FF_SIMSUN,FS_BOLD,12);
$graph->title->SetColor("darkred");
// Setup font for axis
$graph->xaxis->SetFont(FF_SIMSUN,FS_NORMAL,10);
$graph->yaxis->SetFont(FF_SIMSUN,FS_NORMAL,10);
// Show 0 label on Y-axis (default is not to show)
$graph->yscale->ticks->SupressZeroLabel(false);
// Setup X-axis labels
$graph->xaxis->SetTickLabels($datax);
$graph->xaxis->SetLabelAngle(50);
// Create the bar pot
Vendor('Jpgraph.jpgraph_bar');
$bplot = new \BarPlot($datay);
$bplot->SetWidth(0.6);
// Setup color for gradient fill style
$bplot->SetFillGradient("navy:0.9","navy:1.85",GRAD_LEFT_REFLECTION);
// Set color for the frame of each bar
$bplot->SetColor("white");
$graph->Add($bplot);
// Finally send the graph to the browser
$graph->Stroke();
好了,我们来访问一下。
这里面有一个问题,就是中文乱码,其实我之前已经改过两个地方。
①在jpgraph_ttf.inc.php文件中将中文处理的一段改成return $aTxt;
②$graph->title->SetFont(FF_SIMSUN,FS_BOLD,12); 把FF_FONT1改成windows下已经有的FF_SIMSUN
这样就可以正常显示了中文了;