免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1664 | 回复: 1
打印 上一主题 下一主题

PHP call GNUPlot to create chart [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-06-06 06:28 |只看该作者 |倒序浏览
Sorry, my English is bad. But I have not Chinese input type in my system. very sorry!

    I just finish a project that display chart graph. At biganing, I use the JpGraph to create chart. but JpGraph can't create the it better. And JpGraph is very slow if have many data(have max then 50000 line data from SQL server and use it to draw chart). The CPU used 99% when I browser. and must set php.ini to change the memory_limit=32M. memory and time used very many too.

    now, I use a shell script to create the chart, and use PHP call this shell script to  get chart graph. That very fast and not use many memory.

    Folowing is my code.

  1. bash script:  plot
  2. #!/bin/bash
  3. . config
  4. echo "SELECT nm_t,$4 FROM $tablename WHERE \
  5.       nm_gap=$1 AND nm_t>;=$2 AND nm_t<=$3 GROUP BY nm_t;" \
  6.       | mysql $dbname --user=$dbuser --pass=$dbpass --silent \
  7.       >; plot.dat

  8. gnuplot << ENDOFINPUT
  9. set terminal png color
  10. set xdata time
  11. set timefmt "%Y%m%d%H%M%S"
  12. set format x "%Y\n%m/%d\n%H:%M"
  13. set size 1.4,0.7
  14. set title "Cosmic rays variations"
  15. set nokey
  16. set grid
  17. plot "plot.dat" using 1:2 with lines
  18. ENDOFINPUT


  19. php file: plot.php
  20. <?php
  21. isset($_GET['fromYear']) ? $fromYear  = $_GET['fromYear']  : $fromYear= gmdate("Y");
  22. isset($_GET['toYear'])   ? $toYear    = $_GET['toYear']    : $toYear  = gmdate("Y");
  23. isset($_GET['fromMonth'])? $fromMonth = $_GET['fromMonth'] : $fromMonth= gmdate("m");
  24. isset($_GET['toMonth'])  ? $toMonth   = $_GET['toMonth']   : $toMonth = gmdate("m");
  25. isset($_GET['fromDay'])  ? $fromDay   = $_GET['fromDay']   : $fromDay = gmdate("d")-1;
  26. isset($_GET['toDay'])    ? $toDay     = $_GET['toDay']     : $toDay   = gmdate("d")-1;
  27. isset($_GET['fromMin'])  ? $fromMin   = $_GET['fromMin']   : $fromMin = 0;
  28. isset($_GET['toMin'])    ? $toMin     = $_GET['toMin']     : $toMin   = 0;
  29. isset($_GET['fromHour']) ? $fromHour  = $_GET['fromHour']  : $fromHour= 0;
  30. isset($_GET['toHour'])   ? $toHour    = $_GET['toHour']    : $toHour  = 23;
  31. isset($_GET['timeSlot']) ? $timeSlot  = $_GET['timeSlot']  : $timeSlot= 60;
  32. isset($_GET['dataType']) ? $dataType  = $_GET['dataType']  : $dataType= 0;

  33. $gap = $timeSlot;
  34. if ($dataType == 0)$coly = "nm_on";
  35. if ($dataType == 1)$coly = "nm_off";

  36. if($fromMonth<10)$fromMonth = "0".$fromMonth;
  37. if($toMonth<10)  $toMonth   = "0".$toMonth;
  38. if($fromDay<10)  $fromDay   = "0".$fromDay;
  39. if($toDay<10)    $toDay     = "0".$toDay;
  40. if($fromHour<10) $fromHour  = "0".$fromHour;
  41. if($toHour<10)   $toHour    = "0".$toHour;
  42. if($fromMin<10)  $fromMin   = "0".$fromMin;
  43. if($toMin<10)    $toMin     = "0".$toMin;

  44. $from = $fromYear.$fromMonth.$fromDay.$fromHour.$fromMin."00";
  45. $to   = $toYear.$toMonth.$toDay.$toHour.$toMin."60";

  46. passthru("/bin/bash plot ".escapeshellcmd($gap)." "
  47.                           .escapeshellcmd($from)." "
  48.                           .escapeshellcmd($to)." "
  49.                           .escapeshellcmd($coly));
  50. exit;
  51. ?>;
复制代码



like this to display chart graph.

<img src="plot.php?title=&dataType=0&timeSlot=86400&fromYear=2003
         &toYear=2003&fromMonth=1&toMonth=12&fromDay=1&toDay=31
         &fromHour=0&toHour=23&fromMin=0&toMin=59">;

论坛徽章:
0
2 [报告]
发表于 2005-06-12 20:20 |只看该作者

PHP call GNUPlot to create chart

我想这篇文章对那些要用PHP做图表的人一定有所帮助,怎么没人关心呢?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP