PHP drawing--Drawing with Jpgraph

Source: Internet
Author: User

 1.To support Chinese, you need to useSimhei.ttfand theSIMSUN.TTCthe two fonts,When you use Chinese, you need to useSetFont (ff_simsun,fs_bold)sets the font. put the required fonts into the Src\fonts\ directory under the project directory in jpgraph.php , there is the following code that sets the font file path ////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.

If you want to modify the path of the file first, under Window
Modify the jpgraph_ttf.inc.php file$jpgraph _font_dir = dirname (__file__). ' \\fonts\\ ';//change the path of the font from the original/fonts/to \\fonts\\ if not modified under Windows will report the following error
To solve the Chinese problem:If your file is encoded asUtf-8, modify the method as follows 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);       } modified 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: modify in the program $title = "Flow Chart";
$title = Iconv ("UTF-8", "gb2312", $title);
$graph->title->set ($title);
Note:JpgraphThe default display of Chinese characters is to think of Chinese character codinggb2312,translates toUtf-8Show again later.
in that case, if your file code isGb2312,setfontthe first parameter of a method isFf_simsuncan be.
If you areUtf-8coding You also need to convert Chinese character coding intogb2312so that your characters can be displayed normally.


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 split//$p 1->value->setfont (ff_simsun,fs_bold,20);//Set Font/* Note text */$p 1-> Setlegends ($vote _content); $graph->legend->setfont (Ff_simsun,fs_bold);//Set comment text font $graph->legend->pos (0.05,0.3, "right", "center");//control the position of the note 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--Drawing with Jpgraph

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.