Heim >Backend-Entwicklung >PHP-Tutorial >php中jpgraph库的使用

php中jpgraph库的使用

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-23 13:35:121130Durchsuche

用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();
?>


下面是结果:



Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn