JPGraph中文乱码问题

主要是加上SetFont 方法

$graph->title->SetFont(FF_SIMSUN,FS_BOLD); 


jpgraph处理有中文字符时都会转成utf8编码后显示,我们只需注释掉相关的代码就可以了。

dotproject苷特图中文乱码解决具体步骤如下:

1。修改jpgraph库

打开dotproject /lib/jpgraph/jpgraph/src/jpgraph.php文件,找到下面代码段

    function convert($atxt,$aff) {
 if( language_cyrillic ) {
     if( cyrillic_from_windows ) {
  $atxt = convert_cyr_string($atxt, "w", "k");
     }
     $isostring = convert_cyr_string($atxt, "k", "i");
     $unistring = languageconv::iso2uni($isostring);
     return $unistring;
 }/* 注释掉下面代码段
 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::raise('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);
 }注释到此结束*/
 else
     return $atxt;
    }

2.修改dotproject中用到jpgraph的模块

  a.  改project模块

打开dotproject/modules/projects/gantt.php文件,修改文件中下面的代码

将所有

arialbd.ttf

simsum.ttc

替换

将所有

ff_arial

ff_simsun

替换

注释掉下面的代码

 //if ( $locale_char_set=='utf-8' && function_exists("utf8_decode") ) {
 // $name = utf8_decode($name);
 //}

b.同理修改dotproject/modules/tasks/gantt.php文件

例子:


  
  


jpgraph/src/jpgraph.php
  替换 $font_family=FF_FONT1 为 $font_family=FF_SIMSUN
  如果和我一样使用utf-8编码,那么简单的修改一下 jpgraph_gb2312.php 中的

 function gb2utf8($gb) {
     // 新加一行  , 如果是使用gb2312编码,这里看名字就知道什么意思了.
       return $gb 
     // .........
 }

 直接看例字:

jpgraph/line.php 

 
/**
 * http://www.zhaipeng.cn
 * 2008-1-30
 * JPGRAPH 生成X-Y线形统计图
*/
include(’src/jpgraph.php’); //Graph类
include(’src/jpgraph_line.php’); //LinePlot 类
$data = array(19 , 23 , 34 ,36, 50 , 60 , 65, 70 , 78); //模拟数据
$graph = new Graph($width = 400 , $height = 300); //创建新的Graph对象
$graph->SetScale(”textlin”); //设置刻度模式
$graph->img->SetMargin(30 , 30 , 80 , 30) ; //设置图表边界
$graph->title->Set(”简体中文 繁體中文 test”) ; //设置图表标题
//$graph->title->SetFont(FF_SIMSUN,FS_BOLD); // 设置中文字体
$lineplot = new LinePlot($data); //创建新的LinePlot对象
$lineplot->SetLegend(”数据1);//设置图例文字
$graph->subtitle->SetFont(FF_SIMSUN);
$graph->subsubtitle->SetFont(FF_SIMSUN);
$lineplot->SetColor(”red”); //设置曲线颜色
$graph->Add($lineplot); //在统计图上绘制曲线
$data2 = array(20 ,30 ,45 , 23 , 45 , 69 , 60 , 79 , 80);
$lineplot = new LinePlot($data2); //创建新的LinePlot对象
$lineplot->SetLegend(”数据2);//设置图例文字
$lineplot->SetColor(”blue”); //设置曲线颜色
$graph->Add($lineplot); //在统计图上绘制曲线
$graph->Stroke() ; //输出图像

jpgraph/line.php 
PHP生成柱形图

/**
 * http://www.zhaipeng.cn
 * 2008-1-30
 * JPGRAPH 生成柱形图
 */
include('src/jpgraph.php');
include('src/jpgraph_bar.php'); 
$data = array(18 ,23, 26 , 27 , 48 , 25 , 49); //模拟数据
$graph = new Graph(400 , 300);
$graph->SetScale("textlin"); //设置刻度模式
$graph->SetShadow(); //设置阴影
$graph->img->SetMargin(40 , 30 , 20 , 40) ;//设置边距
$barplot = new BarPlot($data);
$barplot->SetFillColor('blue') ; // 设置颜色
$barplot->value->Show(); //设置显示数字
$graph->Add($barplot); //将柱形图添加到图像中
//设置标题和X-Y轴标题
$graph->title->Set('测试柱形图');
$graph->xaxis->title->Set("月份");
$graph->yaxis->title->Set("总金额(元)");
 
/**
* 设置字体,因为修改过jpgraph.php 所以可以不使用
$graph->title->SetFont(FF_SIMSUN , FS_BOLD);
$graph->yaxis->title->SetFont(FF_SIMSUN , FS_BOLD);
$graph->xaxis->title->SetFont(FF_SIMSUN , FS_BOLD);
*/
 
$graph->Stroke();

JPGRAPH 生成饼形图

JPGRAPH 生成饼形图

/**
 * http://www.zhaipeng.cn
 * 2008-1-30
 * JPGRAPH 生成饼形图
 */
 include(’src/jpgraph.php’);
 include(’src/jpgraph_pie.php’);
$data = array(18 ,23, 26 , 27 , 48 , 25 , 49); //模拟数据
$graph = new PieGraph(400 , 300);
$graph->SetShadow();$graph->title->Set("饼形图");
$pieplot = new PiePlot($data);
$graph->Add($pieplot);
$graph->Stroke();

JPGRAPH 生成3D饼图

/**
 * http://www.zhaipeng.cn
 * 2008-1-30
 * JPGRAPH 生成3D饼图
 */
include(’src/jpgraph.php’);
include(’src/jpgraph_pie.php’);
include(’src/jpgraph_pie3d.php’); 
$data = array(18 ,23, 26 , 27 , 48 , 25 , 49 , 50 , 45 , 23 , 20 ,30); //模拟数据
$month = array('一月','二月','三月','四月' , '五月' , '六月' , '七月' , '八月' , '九月','十月','十一月','十二月');
$graph = new PieGraph(400 , 300);
$graph->SetShadow();
$graph->title->Set("3D饼图");
$pieplot = new PiePlot3D($data);
$pieplot->SetCenter(0.4) ; //设置饼图的中心位置
$pieplot->SetLegends($month); //设置图例
$graph->Add($pieplot);
$graph->Stroke('3d.jpg');



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值