Home > Backend Development > PHP Tutorial > php中jpgraph库的使用

php中jpgraph库的使用

WBOY
Release: 2016-06-23 13:35:12
Original
1097 people have browsed it

用Jpgraph,只要了解它的一些内置函数,可以轻松得画出折线图、柱形图、饼状图等图表。


  首先要保证PHP打开了Gd2的扩展:


  打开PHP.ini,定位到extension=php_gd2.dll,把前面的分号删掉。


  然后下载Jpgraph,http://www.aditus.nu/jpgraph/,解压到一个文件夹中。如 d:\wamp\www\jpgraph。


  打开PHP.ini,修改include_path参数,增加Jpgraph的路径,如include_path=",;d:\wamp\www\jpgraph",重启Apache服务。

  这样环境就配好了

      下面是一个使用的例子

   include("./jpgraph/src/jpgraph.php");              //Graph 类
   include("./jpgraph/src/jpgraph_line.php");         //LinePlot类


   $graph = new  Graph(400, 300);//创建新的Graph对象
   $graph->SetScale("textlin");//设置刻度样式
   $graph->img->SetMargin(30,30,80, 30);//设置图标边界
   $graph->title->Set("Year to Date Cost");//设置图标标题


   //绘制曲线
   //将要用于图表创建的数据存放在数组中
   $data = array(19,23,34,38,45,67,71,78,85,87,90.96);
   $lineplot = new LinePlot($data);
   $lineplot->SetLegend("Amount(M dollars)");
   $lineplot->SetColor("green");


   //讲曲线放在图表中
   $graph->Add($lineplot);
    
   //输出图表
   $graph->Stroke();
?>


下面是结果:



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template