解决Windows下JpGraph中文乱码问题
JpGraph中文乱码的问题很头痛,网上的教材大部分都没什么效果,历经一下午的测试,终于找到了一种方式,操作如下:
适用版本2.3,其他版本没有测试
1. 在jpgraph/src/jpgraph.php中最上面添加下面两行代码
define("CACHE_DIR", "./cache");
define("TTF_DIR", "c:/windows/fonts/");
上面两行可有有无,测试发现并没有带来什么样的改变.作用是:设置字体所在的目录和缓存所在的目录
查找$font_family=FF_FONT1替换为$font_family=FF_SIMSUN
2. 在jpgraph/src/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);
}
elseif( $aFF === FF_CHINESE ) {
if( !function_exists('iconv') ) {
JpGraphError::RaiseL(25006);
//('Usage of FF_CHINESE (FF_BIG5) font family requires that your PHP setup has the iconv() function. By default this is not compiled into PHP (needs the "--width-iconv" when configured).');
}
return iconv('BIG5','UTF-8',$aTxt);
}*/
3. 页面使用utf-8编码,设置图标标题中包含中文时,这样使用:
$graph->title->Set("我的一个测试Accumulated bar plots");
$graph->xaxis->title->Set("我的X-title");
$graph->yaxis->title->Set("你的Y-title");
$graph->title->SetFont(FF_SIMSUN,FS_BOLD);
$graph->yaxis->title->SetFont(FF_SIMSUN,FS_BOLD);
$graph->xaxis->title->SetFont(FF_SIMSUN,FS_BOLD);