jpgraph3.0.7 入门教程

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

这样就可以正常显示了中文了;

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值