How to solve the Chinese garbled characters in JpGraph

Source: Internet
Author: User
JpGraph is a very good graph class library. we can directly use it to generate various bar charts, pie charts, line charts, and text descriptions. there is no problem when adding English numbers, however, garbled characters may be found when Chinese characters are added, and some Chinese characters are sorted out... jpGraph is a very good graph class library. we can directly use it to generate various bar charts, pie charts, line charts, and text descriptions. there is no problem when adding English numbers, however, garbled characters are found when Chinese characters are added. This section provides some solutions to the JpGraph Chinese garbled characters for your reference.

Why does JpGraph contain Chinese garbled characters?

In JpGraph, the character string is converted to utf8 by default. However, if your file is utf8 and you want to use a Chinese font, it will be converted again and the result will be converted again, garbled characters appear.

How to solve Chinese garbled characters in JpGraph

To solve the problem of JpGraph Chinese garbled characters, take the code snippet of the previous article as follows:

// Set the title font and size of the chart. $ graph-> title-> Set ("Accumulated bar plots "); $ graph-> xaxis-> title-> Set ("X-title"); $ graph-> yaxis-> title-> Set ("Y-title "); // set the font and size of the title corresponding to the title above $ graph-> title-> SetFont (FF_FONT1, FS_BOLD ); $ graph-> yaxis-> title-> SetFont (FF_FONT1, FS_BOLD); $ graph-> xaxis-> title-> SetFont (FF_FONT1, FS_BOLD ); // change it to // Set the title font, size $ graph-> title-> Set (iconv ("UTF-8", "GB2312 // IGNORE ", "Blog info statistics table"); $ graph-> xaxis-> title-> Set (iconv ("UTF-8", "GB2312 // IGNORE ", "X-title"); $ graph-> yaxis-> title-> Set (iconv ("UTF-8", "GB2312 // IGNORE ", "Y-title"); // corresponds to the title above, set the font and size of the title $ graph-> title-> SetFont (FF_SIMSUN, FS_BOLD ); $ graph-> yaxis-> title-> SetFont (FF_SIMSUN, FS_BOLD); $ graph-> xaxis-> title-> SetFont (FF_SIMSUN, FS_BOLD );

Using the php function from the UTF-8 to GB2312 according to the Chinese language, remember iconv due to a bug, iconv in conversion character "-" to gb2312 error, therefore, add "// IGNORE" after the code to be converted ".

FF_SIMSUN indicates simplified Chinese and the corresponding font file is simsun. ttc. although FF_CHINESE and FF_BIG5 also indicate Chinese, their corresponding font files are different, so do not make a mistake.

To solve the Chinese garbled characters in JpGraph,The complete code for debugging in this example is as follows:

Require_once ('jpgraph/jpgraph. php '); require_once ('jpgraph/jpgraph_bar.php'); $ data1y = array (,); $ data2y = array ); // Create the graph. these two CILS are always required $ graph = new Graph (500,400); $ graph-> SetScale ("textlin"); $ graph-> SetShadow (); $ graph-> img-> SetMargin (,); // you can specify the image margins. // 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); // Set the title font style $ graph-> title-> Set ("UTF-8 ", "GB2312 // IGNORE", "blog info statistics table"); $ graph-> xaxis-> title-> Set (iconv ("UTF-8 ", "GB2312 // IGNORE", "X-title"); $ graph-> yaxis-> title-> Set (iconv ("UTF-8", "GB2312 // IGNORE ", "Y-title"); $ 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 ();

Of course, I only introduced one method here. Another method is to modify the source code, but it is not recommended because I think modifying the source code may cause unexpected troubles elsewhere.

To use JpGraph, you need to know the information about the version, running server, and operating system. you cannot use it. Otherwise, there will be a lot of trouble. so far, there will be so much introduction to JpGraph.


Permanent address:

Reprint at will ~ Please bring the tutorial URL ^

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.