??1.to support chinese, we need to useSimhei.ttfand theSIMSUN.TTCthe two fonts,when using chinese, you need to useSetFont (ff_simsun,fs_bold)Sets the Font. put the required fonts into the Src\fonts\ folder under the project folder in jpgraph.php , There is a section of code that sets the path of the font file. ////Setup path for western/latin TTF fonts//if (!defined (' ttf_dir ')) {if (strstr (php_os, ' WIN ')) {$sroot = getenv (' SystemRoot ');if (empty ($sroot)) {$t = new Errmsgtext ();$msg = $t->get ($file, $lineno);die ($msg); }else {define (' ttf_dir ', $sroot. ' /fonts/'); }} else {define (' ttf_dir ', '/usr/share/fonts/truetype/'); }} 2. It is important to note that: to applyJpgraph, you havePHPmust be turned On.GD2Extension.
assume that the path to the file must be changed first under window
Change jpgraph_ttf.inc.php file$jpgraph _font_dir = dirname (__file__). ' \\fonts\\ ';//change The path of the font from the original/fonts/to \\fonts\\ assume that no changes in Windows will report the following error
to solve the Chinese problem:Let's say your file is encoded asutf-8, change methods such as the following
Method One:Find ElseIf ($aFF = = = Ff_simsun) { //do Chinese convers ion if ($this->g2312 = = Null) { &NBS P include_once ' jpgraph_gb2312.php '; $this->g2312 = new GB 2312toutf8 (); } return $this->g2312-& Gt;gb2utf8 ($aTxt); } change to ElseIf ($aFF = = = Ff_simsun) { & nbsp //do Chinese conversion /* &NBSP ; if ($this->g2312 = = Null) { include_once ' jpgraph_gb2312 . PHP '; $this->g2312 = new Gb2312toutf8 (); & nbsp } return $this->g2312->gb2utf8 ($aTxt); &N Bsp */ return $aTxt; }
method Two: Change in the program $title = "Flow Chart";
$title = Iconv ("UTF-8", "gb2312", $title);
$graph->title->set ($title);
note:Jpgraphthe default display of Chinese characters when the Chinese character coding thinkgb2312,translates toUtf-8Show again Later.
in This case, suppose your file encoding is Gb2312,setfont the first parameter of a method is Ff_simsun We Can.
Suppose you are Utf-8 coding you need to convert Chinese character coding into gb2312 . This way your Chinese characters are good enough to show.
The code is as Follows:
<?php/** * Generate 3D pie chart using jpgraph * */include ' src/jpgraph.php '; include ' src/jpgraph_pie.php '; include ' Src/jpgraph_ pie3d.php ';//refer to the class file containing the 3D pie Pieplot3d Object
$result = Array (5,8,11,1,1,1), $vote _content = array ("zhang san", "lili", "lili", "zhang san", "lili", "lili"); $title = ' title ';
$graph = new Piegraph (500,245);//create image $graph->setshadow ();//create image Shadow $graph->tabtitle->setfont (ff_simsun,fs_ Bold,14);//set caption Font $graph->tabtitle->set ($title);//output title $graph->title->setcolor ("darkblue");//define title Color
$p 1 = new Pieplot3d ($result);//create image//$p 1->settheme ("water");//control image color//$p 1->setcenter (0.4);//set image position//$p 1- >setsize (0.4);//set the image size//$p 1->setheight (20);//set The height of the pie chart//$p 1->setangle (45);//set The tilt angle of the image//$p 1->explode (array (5,40,10,30,20));//control pie chart cutting//$p 1->value->setfont (ff_simsun,fs_bold,20);//set font/* gaze text */$p 1-> Setlegends ($vote _content); $graph->legend->setfont (ff_simsun,fs_bold);//set gaze text font $graph->legend->pos (0.05,0.3, "right", "center");//control The position of the gaze text $graph->legend->setshadow ();//boundary $graph->legend->setlayout ( Legend_vert);//set Legend Style and location
$graph->add ($p 1);//add data $graph->stroke ();//generate image
PHP drawing-using Jpgraph Drawing