请选择 进入手机版 | 继续访问电脑版
绿茶科技社区

PHP生成折线图和饼图等

2019-11-15 02:21
1123

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
pchart类库下载(地址:http://pchart.sourceforge.net/documentation.php) , 下载过后其中也有相应的例子,供选择
生成折线图
  1. include("pChart/pData.class");  

  2. include("pChart/pChart.class");  

  3. // Dataset definition

  4. $DataSet = new pData;

  5. $DataSet->AddPoint(array(100,320,200,10,43),"Serie1");

  6. $DataSet->AddPoint(array(20190726,20190727,20190728,20190729,20190730),"Serie3");

  7. $DataSet->AddSerie("Serie1");

  8. $DataSet->SetAbsciseLabelSerie("Serie3");

  9. // Initialise the graph   

  10. $Test = new pChart(700,230);

  11. $Test->setFontProperties("Fonts/tahoma.ttf",8);

  12. $Test->setGraphArea(85,30,650,200);

  13. $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);

  14. $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);

  15. $Test->drawGraphArea(255,255,255,TRUE);

  16. $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);

  17. $Test->drawGrid(4,TRUE,230,230,230,50);

  18. $Test->setFontProperties("Fonts/tahoma.ttf",6);

  19. $Test->drawTreshold(0,143,55,72,TRUE,TRUE);

  20. $Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());

  21. $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);

  22. //生成图表

  23. $imageFile = "1.png";

  24. $Test->Render($imageFile);

  25. echo '<img src="'.$imageFile.'">';
复制代码
生成饼图
  1. <?php

  2. /*

  3.      Example13: A 2D exploded pie graph

  4. */

  5. // Standard inclusions   

  6. include("pChart/pData.class");

  7. include("pChart/pChart.class");

  8. // Dataset definition

  9. $DataSet = new pData;

  10. $DataSet->AddPoint(array(100,320,200,10,43,417),"Serie1");

  11. $DataSet->AddPoint(array("20190726","20190727","20190728","20190729","20190730","20190731"),"Serie2");

  12. $DataSet->AddAllSeries();

  13. $DataSet->SetAbsciseLabelSerie("Serie2");

  14. // Initialise the graph

  15. $Test = new pChart(500,200);

  16. $Test->setFontProperties("Fonts/tahoma.ttf",8);

  17. $Test->drawFilledRoundedRectangle(7,7,293,193,5,240,240,240);

  18. $Test->drawRoundedRectangle(5,5,295,195,5,230,230,230);

  19. // Draw the pie chart

  20. $Test->AntialiasQuality = 0;

  21. $Test->setShadowProperties(2,2,200,200,200);

  22. $Test->drawFlatPieGraphWithShadow($DataSet->GetData(),$DataSet->GetDataDescription(),120,100,60,PIE_PERCENTAGE,8);

  23. $Test->clearShadow();

  24. $Test->drawPieLegend(230,15,$DataSet->GetData(),$DataSet->GetDataDescription(),250,250,250);

  25. $imageFile = 'example12.png';

  26. $Test->Render($imageFile);

  27. echo '<img src="'.$imageFile.'">';

  28. ?>
复制代码

分享到 :
0 人收藏

3 个回复

倒序浏览
施杨  金牌会员 | 2019-11-15 03:00:16
这么强,支持楼主,佩服
sparkdev  高级会员 | 2019-11-26 14:09:27
看帖要回,回帖才健康,在踩踩,楼主辛苦了!
陈希章  高级会员 | 2019-11-29 14:43:01
撸过
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

举报|Archiver|手机版|小黑屋|Lvchakeji Inc.  

Powered by Discuz! X3.3 © 2001-2016 Comsenz Inc.

返回顶部