解决DotProject 甘特图中文乱码
2008-07-01 14:47:29
版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://juwen.blog.51cto.com/135311/84919 |
抄了网上的一个方法,我输出甘特图时进行编码转换,好处就是不用对系统做什么修改。
DotProject版本:2.1.1
修改modules\tasks\gantt.php
显示中文的内容加上iconv("utf-8","GB2312","内容")转换即可。
需要修改的内容:
第一处:$projects[$project_id]['project_name'] = $AppUI->_('Todo for').' '.iconv("utf-8","GB2312",dPgetUsername($user_id));
第二处:$graph->scale->tableTitle->Set(iconv("utf-8","GB2312",$projects[$project_id]['project_name']));
第三处:
if ( $locale_char_set=='utf-8' && function_exists('utf8_decode') ) { //$name = utf8_decode($name); //<--注释掉 $name=iconv("utf-8","GB2312",$name);//<--增加的 } 第四处:
在if ($caller == 'todo') { ... } 后面增加 $pname=iconv("utf-8","GB2312",$pname); 第五处:
$vline = new GanttVLine($today, iconv("utf-8","GB2312",$AppUI->_('Today', UI_OUTPUT_RAW))); 参考一下,在我实际使用过程中发现此方法不可行,应该是大家使用的dotproject版本不一致。我尝试调用jpgraph,测试程序如下index1.php
<?php
include ("lib/jpgraph/src/jpgraph.php"); include ("lib/jpgraph/src/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'); // 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); $graph->Add($b1); // Finally output the image
$graph->Stroke(); ?>
很痛苦地发现,出来的中文也是乱码,因此我觉得这个乱码的问题不能单单在dotproject里解决,必须从根部着手,我猜测出现乱码有两个原因,一个是字库问题,一个就是代码的问题。我从网上下载了最新版本的jpgraph(2.3.3),同时在lib/jgraph,新增fonts目录,将使用到的字体放到目录里,然后修改配置文件使其使用目录里面的字体。测试结果解决问题。
修改地方:
modules\tasks\gantt.php
FF_ARIAL 替换成 FF_SIMSUN
arialbd.ttf 替换成 simsun.ttc
大概有4、5处吧。
![]() 本文出自 “jonsoft” 博客,请务必保留此出处http://juwen.blog.51cto.com/135311/84919 本文出自 51CTO.COM技术博客 |
附件下载:
中文正常显示
中文正常显示


juwen
博客统计信息
热门文章
最新评论
友情链接
