文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>生成统计图类pchart文档

生成统计图类pchart文档

时间:2010-05-11  来源:xhq6632

Documentation
This documentation has been last updated on 06/18/2008.

pChart - a chart drawing library
Thank you for using pChart, we hope that you'll find the answer to your questions in this documentation. If not, feel free to use the dedicated sourceforge forum and tracker. Drawing a chart can be cut in 3 parts : First, get access to the data and prepare it to be graphed ( you can use the pData class to help ). Second, prepare the graph design : rounded corners, freaky background, drawing area and then draw the chart! Last step, put some labels, title and legends. Your chart can now be saved in a web server folder or sent directly to the client browser.

Using the library
This class can be invoked for realtime picture drawing or cron/scheduled tasks. Rendering a graph is CPU consuming, we recomment that all static graphs ( or with a renewal interval of more than 10 minutes ) should be computed from a cron job, this also apply to web sites serving a lot of page views.

pChart is using the GD library to create pictures. You must compile the GD library with the freetype extension when installing PHP on a linux server. On windows operating system you must add the GD extension in your php.ini file. GD support is a mandatory prerequisite and cannot be overriden. You can use the following tutorial if you don't know how to install it on a linux server.
If you plan to use pChart on a production web service, keep an eye on project updates & progress list. We'll try to focus on increasing the graphical render speed.
A section of this documentation is dedicated on how to use pChart to render scheduled jobs ( windows & linux )

This graph is a simple -naked- rendering using the pChart library:
view plaincopy to clipboardprint?
  1. <?php   
  2. // Standard inclusions      
  3. include("pChart/pData.class");   
  4. include("pChart/pChart.class");   
  5.   
  6. // Dataset definition    
  7. $DataSet = new pData;   
  8. $DataSet->AddPoint(array(1,4,3,2,3,3,2,1,0,7,4,3,2,3,3,5,1,0,7));   
  9. $DataSet->AddSerie();   
  10. $DataSet->SetSerieName("Sample data","Serie1");   
  11.   
  12. // Initialise the graph   
  13. $Test = new pChart(700,230);   
  14. $Test->setFontProperties("Fonts/tahoma.ttf",10);   
  15. $Test->setGraphArea(40,30,680,200);   
  16. $Test->drawGraphArea(252,252,252);   
  17. $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);   
  18. $Test->drawGrid(4,TRUE,230,230,230,255);   
  19.   
  20. // Draw the line graph   
  21. $Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());   
  22. $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);   
  23.   
  24. // Finish the graph   
  25. $Test->setFontProperties("Fonts/tahoma.ttf",8);   
  26. $Test->drawLegend(45,35,$DataSet->GetDataDescription(),255,255,255);   
  27. $Test->setFontProperties("Fonts/tahoma.ttf",10);   
  28. $Test->drawTitle(60,22,"My pretty graph",50,50,50,585);   
  29. $Test->Render("Naked.png");   
  30. ?>   
   <?php
   // Standard inclusions   
   include("pChart/pData.class");
   include("pChart/pChart.class");

   // Dataset definition 
   $DataSet = new pData;
   $DataSet->AddPoint(array(1,4,3,2,3,3,2,1,0,7,4,3,2,3,3,5,1,0,7));
   $DataSet->AddSerie();
   $DataSet->SetSerieName("Sample data","Serie1");

   // Initialise the graph
   $Test = new pChart(700,230);
   $Test->setFontProperties("Fonts/tahoma.ttf",10);
   $Test->setGraphArea(40,30,680,200);
   $Test->drawGraphArea(252,252,252);
   $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
   $Test->drawGrid(4,TRUE,230,230,230,255);

   // Draw the line graph
   $Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());
   $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);

   // Finish the graph
   $Test->setFontProperties("Fonts/tahoma.ttf",8);
   $Test->drawLegend(45,35,$DataSet->GetDataDescription(),255,255,255);
   $Test->setFontProperties("Fonts/tahoma.ttf",10);
   $Test->drawTitle(60,22,"My pretty graph",50,50,50,585);
   $Test->Render("Naked.png");
   ?>
  
Icons embeding the documentation are created and released by http://www.famfamfam.com/lab/icons/silk/ under the GNU 2.5 license. The javascript syntaxhighlighter library used to display PHP & JS code in this documentation is released under the GNU license.
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载