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.
-
- include (".. /jpgraph.php ");
- include (".. /jpgraph_line.php ");
-
- $ydata = Array (11,3,8,12,5,1,9,13,5,7);
- $y 2data = Array (354,200,265,99,111,91,198,225,293,251);
- $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");
-
- //Create the graph. These calls is always required
- $graph = New Graph (800,400,"Auto");
- $graph ->img->setmargin (40,40,20,40);
-
- $graph ->title->setfont (Ff_simsun,fs_bold);
- $title = "Show pv/display IP" ;
- $graph ->title->set ($title);
-
- $graph ->setscale ("Textlin");
- $graph ->sety2scale ("Lin");
-
- $graph ->xaxis->title->set ("Time");
- $graph ->xaxis->title->setfont (Ff_simsun,fs_bold);
- $graph ->xaxis->setticklabels ($datax);
-
- $graph ->yaxis->title->set ("Display PV");
- $graph ->yaxis->setcolor ("Blue");
- $graph ->yaxis->title->setfont (Ff_simsun,fs_bold);
-
- $graph ->y2axis->title->set ("Display IP");
- $graph ->y2axis->setcolor ("Orange");
- $graph ->y2axis->title->setfont (Ff_simsun,fs_bold);
-
- $lineplot = New LinePlot ($ydata);
- $lineplot ->setcolor ("Blue");
- $lineplot ->setweight (2);
- $lineplot ->setlegend ("Display PV");
- $graph ->legend->setfont (Ff_simsun,fs_bold);
-
- $lineplot 2 = New LinePlot ($y 2data);
- $lineplot 2 ->setcolor ("Orange");
- $lineplot 2 ->setweight (2);
- $lineplot 2 ->setlegend ("Display IP");
-
-
- $graph ->add ($lineplot);
- $graph ->addy2 ($lineplot 2);
-
- //Display the graph
- $graph ->stroke ();
- ?>
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 ...