Home  >  Article  >  Backend Development  >  [Original] Solving the problem of Chinese garbled characters in jpgraph_PHP tutorial

[Original] Solving the problem of Chinese garbled characters in jpgraph_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:35:521049browse

php jpgraph library is very powerful and can generate images in the background

Backend generation is very useful when you need to export chart-type reports. Of course, front-end visualization still requires the use of highcharts/echarts/anycharts and other class libraries

What is more troublesome is the problem of garbled Chinese characters. There are garbled characters in three places:

  • legend
  • setStickLabels
  • title

First explain my environment and version:

  • Ubuntu12.04
  • PHP 5.3.10-1
  • Jpgraph 3.5.0b1
  • File fileencoding=utf-8

Legend garbled characters

  //jpgraph_legend.inc.php
  3 class Legend {
  2     public $txtcol=array();
  1     //public $font_family=FF_DEFAULT,$font_style=FS_NORMAL,$font_size=8; // old. 12
  0     public $font_family=FF_SIMSUN,$font_style=FS_NORMAL,$font_size=8; // old. 12

Remember to download a copy of simsun.ttc and put it in /usr/share/fonts/truetype

   //jpgraph_ttf.inc.php
  9         elseif( $aFF === FF_SIMSUN ) {
  8             // Do Chinese conversion 
  7             /*
  6             if( $this->g2312 == null ) {
  5                 include_once 'jpgraph_gb2312.php' ;
  4                 $this->g2312 = new GB2312toUTF8();
  3             }
  2             return $this->g2312->gb2utf8($aTxt);
  1              */
  0             return $aTxt;<br />
  1         }

Original article, please indicate when reprinting: http://www.cnblogs.com/phpgcs/

I refer to the above solution:

http://blog.csdn.net/yiping1980/article/details/6023144

Then the next two I think are the places to find the title/stickLabels source code, change FFDEFAULT to FFSIMSUN

It turns out that this is indeed the case, and conveniently these 2 guys are both in the jpgraph.php file

Directly

:%s/FF_DEFAULT/FF_SIMSUN/g

That’s it

title garbled

  2         $this->title = new Text();
  1         $this->title->ParagraphAlign('center');
  0         //$this->title->SetFont(FF_DEFAULT,FS_NORMAL); //FF_FONT2, FS_BOLD<br />
  1         $this->title->SetFont(FF_SIMSUN,FS_NORMAL); //FF_FONT2, FS_BOLD

stickLables garbled characters

  5 class AxisPrototype {
  4     public $scale=null;
  3     public $img=null;
  2     public $hide=false,$hide_labels=false;
  1     public $title=null;
  0     public $font_family=FF_DEFAULT,$font_style=FS_NORMAL,$font_size=8,$label_angle=0;

There is also a place with FF_DEFAULT,

  5 class DisplayValue {
  4     public $margin=5;
  3     public $show=false;
  2     public $valign='',$halign='center';
  1     public $format='%.1f',$negformat='';
  0     private $ff=FF_DEFAULT,$fs=FS_NORMAL,$fsize=8;

Summary:

  • Find the relevant source code (FF_DEFAULT)
  • Modify jpgraphttf.inc.php, $aFF === FFSIMSUN then directly return $aTx

Original article, please indicate when reprinting: http://www.cnblogs.com/phpgcs/

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/742171.htmlTechArticlephp jpgraph library is very powerful and can generate pictures in the background. Background generation is very useful when you need to export chart-type reports. Of course, front-end visualization still requires highcharts/echarts...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn