Jpgraph Chinese characters garbled solution and Example _php tutorial

Source: Internet
Author: User
Tags pear radar
Jpgraph is a very convenient work in the PHP world to do all kinds of charts, histograms, pie charts, radar charts and so on, basically all the charts omnipotent.

In pear, there is also a tool for charting, called Image_graph, the tool is also very powerful, but Jpgraph and image_graph the biggest advantage is that there are a lot of examples and very detailed document description, This makes the jpgraph use is quite convenient.

Finally decided to choose Jpgraph.

Here is a piece of code. At the same time in the use of the process encountered the problem of garbled characters, the reason has been found, but also to explain to you.

If you encounter any problems in the use of jpgraph, you can mail to me, we have been discussing. At the same time, if you have any use of experience, also hope you can send to lamper, let more people share your experience.

 
 
  1. include ("..  /jpgraph.php ");
  2. include ("..  /jpgraph_line.php ");
  3.  
  4. $ydata = Array  (11,3,8,12,5,1,9,13,5,7);
  5. $y 2data = Array  (354,200,265,99,111,91,198,225,293,251);
  6. $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");
  7.  
  8. //Create the graph. These calls is always required
  9. $graph = New   Graph (800,400,"Auto");
  10. $graph  ->img->setmargin (40,40,20,40);
  11.  
  12. $graph  ->title->setfont (Ff_simsun,fs_bold);
  13. $title = "Show pv/display IP"  ;
  14. $graph  ->title->set ($title);
  15.  
  16. $graph  ->setscale ("Textlin");
  17. $graph  ->sety2scale ("Lin");
  18.  
  19. $graph  ->xaxis->title->set ("Time");
  20. $graph  ->xaxis->title->setfont (Ff_simsun,fs_bold);
  21. $graph  ->xaxis->setticklabels ($datax);
  22.  
  23. $graph  ->yaxis->title->set ("Display PV");
  24. $graph  ->yaxis->setcolor ("Blue");
  25. $graph  ->yaxis->title->setfont (Ff_simsun,fs_bold);
  26.  
  27. $graph  ->y2axis->title->set ("Display IP");
  28. $graph  ->y2axis->setcolor ("Orange");
  29. $graph  ->y2axis->title->setfont (Ff_simsun,fs_bold);
  30.  
  31. $lineplot = New  LinePlot ($ydata);
  32. $lineplot  ->setcolor ("Blue");
  33. $lineplot  ->setweight (2);
  34. $lineplot  ->setlegend ("Display PV");
  35. $graph  ->legend->setfont (Ff_simsun,fs_bold);
  36.  
  37. $lineplot 2 = New  LinePlot ($y 2data);
  38. $lineplot 2  ->setcolor ("Orange");
  39. $lineplot 2  ->setweight (2);
  40. $lineplot 2  ->setlegend ("Display IP");
  41.  
  42.  
  43. $graph  ->add ($lineplot);
  44. $graph  ->addy2 ($lineplot 2);
  45.  
  46. //Display the graph
  47. $graph  ->stroke ();
  48. ?>

Note the SetFont method, if your file encoding is the Gb2312,setfont method, the first parameter is Ff_simsun to display the Chinese characters normally

If your file is encoded as Utf-8, add a sentence $title = Iconv ("UTF-8", "gb2312", $title)

In jpgraph.php, there is a sentence:

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, jpgraph default display of Chinese characters is Chinese character coding think gb2312, converted to Utf-8 after the display.

In this case, if your file is encoded as the first parameter of the Gb2312,setfont method, you can Ff_simsun

If you are Utf-8 code you also need to convert Chinese character coding to gb2312, so that your character can display normally.

http://www.bkjia.com/PHPjc/486315.html www.bkjia.com true http://www.bkjia.com/PHPjc/486315.html techarticle Jpgraph is a very convenient work in the PHP world to do all kinds of charts, histograms, pie charts, radar charts and so on, basically all the charts omnipotent. In the pear, there is also a chart ...

  • Related Article

    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.