jpgraph为什么会出现中文乱码
在jpgraph中默认是要把字符串转成utf8的,但是如果你的文件本身就是utf8的,并且要用中文字体,它还会转一遍,结果多转了一次,就会出现乱码。如图所示
jpgraph使用详解之中文乱码解决方法
解决jpgraph中文乱码问题的方法,取前篇的代码片断如下:
//设置图表的标题字体、大小 $graph->title->set(accumulated bar plots); $graph->xaxis->title->set(x-title); $graph->yaxis->title->set(y-title); //和上面标题对应,设置标题的字体和大小 $graph->title->setfont(ff_font1,fs_bold); $graph->yaxis->title->setfont(ff_font1,fs_bold); $graph->xaxis->title->setfont(ff_font1,fs_bold); //把它改为 //设置图表的标题字体、大小 $graph->title->set(iconv(utf-8,gb2312//ignore,网志博客信息统计表)); $graph->xaxis->title->set(iconv(utf-8,gb2312//ignore,x-标题)); $graph->yaxis->title->set(iconv(utf-8,gb2312//ignore,y-标题)); //和上面标题对应,设置标题的字体和大小 $graph->title->setfont(ff_simsun,fs_bold); $graph->yaxis->title->setfont(ff_simsun,fs_bold); $graph->xaxis->title->setfont(ff_simsun,fs_bold);
使用php函数据中文由utf-8转为gb2312,记住由于iconv本身的一个bug,iconv在转换字符-到gb2312时会出错,所以在需要转成的编码后加上 //ignore.
ff_simsun表示中文简体,对应的字体文件是simsun.ttc,虽然ff_chinese和ff_big5也表示中文但是它们对应的字体文件是不同的,所以不要弄错.
解决jpgraph中文乱码问题的方法,下面是本例调试的完整代码:
require_once ('jpgraph/jpgraph.php'); require_once ('jpgraph/jpgraph_bar.php'); $data1y=array(0,8,9,3,5,6); $data2y=array(18,2,1,7,5,4); // create the graph. these two calls are always required $graph = new graph(500,400); $graph->setscale(textlin); $graph->setshadow(); $graph->img->setmargin(40,30,20,40);//设置图形的边距 // create the bar plots $b1plot = new barplot($data1y); $b1plot->setfillcolor(orange); $b1plot->value->show(); $b2plot = new barplot($data2y); $b2plot->setfillcolor(blue); $b2plot->value->show(); // create the grouped bar plot $gbplot = new accbarplot(array($b1plot,$b2plot)); // ...and add it to the graph $graph->add($gbplot); //设置标题字体样式 $graph->title->set(iconv(utf-8,gb2312//ignore,网志博客信息统计表)); $graph->xaxis->title->set(iconv(utf-8,gb2312//ignore,x-标题)); $graph->yaxis->title->set(iconv(utf-8,gb2312//ignore,y-标题)); $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使用介绍也就这么多了.
永久地址:
转载随意~请带上教程地址吧^^
