Jpgraph Chinese character garbled solution and example

Source: Internet
Author: User
Tags radar
JPGRAPH is a very convenient job of various charts in the PHP world, such as bar charts, pie charts, and radar charts. it is basically omnipotent to all charts. In PEAR, there is also a chart-making tool named image_graph. This tool is also very powerful, but jpgraph and image_graph are the biggest advantages in comparison, there are many examples and details. "> <LINKhref =" htt

JPGRAPH is a very convenient job of various charts in the PHP world, such as bar charts, pie charts, and radar charts. it is basically omnipotent to all charts.

In PEAR, there is also a chart-making tool named image_graph. This tool is also very powerful, but jpgraph and image_graph are the biggest advantages in comparison, there are many examples and very detailed documentation, which makes jpgraph quite convenient to use.

Finally, we decided to use jpgraph.

Below is a piece of code. At the same time, I encountered Chinese character garbled characters during usage. the reason has been found and I would like to explain it to you.

If you encounter any problems when using jpgraph, you can MAIL it to me. At the same time, if you have any usage experience, I hope you can send it to LAMPER for more people to share your experience.

 

 
 
  1. Include ("../jpgraph. php ");
  2. Include ("../jpgraph_line.php ");
  3. $ Ydata = array );
  4. $ Y2data = array (354,200,265, 99,111, 91,198,225,293,251 );
  5. $ Datax = array ("2006-01-01", "2006-01-01", "2006-01-01", "2006-01-01", "2006-01-01", "2006-01-01", "2006-01-01", "2006-01-01 ", "2006-01-01", "2006-01-01 ");
  6. // Create the graph. These two cballs are always required
  7. $ Graph = new Graph (800,400, "auto ");
  8. $ Graph-> img-> SetMargin (40, 40, 20, 40 );
  9. $ Graph-> title-> SetFont (FF_SIMSUN, FS_BOLD );
  10. $ Title = "display pv/Display ip ";
  11. $ Graph-> title-> Set ($ title );
  12. $ Graph-> SetScale ("textlin ");
  13. $ Graph-> SetY2Scale ("lin ");
  14. $ Graph-> xaxis-> title-> Set ("Time ");
  15. $ Graph-> xaxis-> title-> SetFont (FF_SIMSUN, FS_BOLD );
  16. $ Graph-> xaxis-> SetTickLabels ($ datax );
  17. $ Graph-> yaxis-> title-> Set ("display pv ");
  18. $ Graph-> yaxis-> SetColor ("blue ");
  19. $ Graph-> yaxis-> title-> SetFont (FF_SIMSUN, FS_BOLD );
  20. $ Graph-> y2axis-> title-> Set ("Show IP ");
  21. $ Graph-> y2axis-> SetColor ("orange ");
  22. $ Graph-> y2axis-> title-> SetFont (FF_SIMSUN, FS_BOLD );
  23. $ Lineplot = new LinePlot ($ ydata );
  24. $ Lineplot-> SetColor ("blue ");
  25. $ Lineplot-> SetWeight (2 );
  26. $ Lineplot-> SetLegend ("display pv ");
  27. $ Graph-> legend-> SetFont (FF_SIMSUN, FS_BOLD );
  28. $ Lineplot2 = new LinePlot ($ y2data );
  29. $ Lineplot2-> SetColor ("orange ");
  30. $ Lineplot2-> SetWeight (2 );
  31. $ Lineplot2-> SetLegend ("Show ip ");
  32. $ Graph-> Add ($ lineplot );
  33. $ Graph-> AddY2 ($ lineplot2 );
  34. // Display the graph
  35. $ Graph-> Stroke ();
  36. ?>

Note the SetFont method. if your file is encoded as gb2312, the first parameter of the SetFont method is FF_SIMSUN.

If your file is UTF-8 encoded, add $ title = iconv ("UTF-8", "gb2312", $ title)

In jpgraph. php, there is such a statement:

Elseif ($ aFF === FF_SIMSUN ){
// Do Chinese conversion
If ($ this-> g2312 = null ){
Include_once 'jpgraph _ gb2312.php ';
$ This-> g2312 = new GB2312toUTF8 ();
}
Return $ this-> g2312-> gb2utf8 ($ aTxt );
}

That is to say, when jpgraph displays Chinese characters by default, it regards the Chinese character encoding as gb2312 and converts it to UTF-8 before display.

In this case, if your file encoding is gb2312, the first parameter of the SetFont method is FF_SIMSUN.

If you are UTF-8 encoded, you must first convert the Chinese character encoding to gb2312 so that your Chinese characters can be properly displayed.

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.