- 论坛徽章:
- 0
|
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.
- bash script: plot
- #!/bin/bash
- . config
- echo "SELECT nm_t,$4 FROM $tablename WHERE \
- nm_gap=$1 AND nm_t>;=$2 AND nm_t<=$3 GROUP BY nm_t;" \
- | mysql $dbname --user=$dbuser --pass=$dbpass --silent \
- >; plot.dat
- gnuplot << ENDOFINPUT
- set terminal png color
- set xdata time
- set timefmt "%Y%m%d%H%M%S"
- set format x "%Y\n%m/%d\n%H:%M"
- set size 1.4,0.7
- set title "Cosmic rays variations"
- set nokey
- set grid
- plot "plot.dat" using 1:2 with lines
- ENDOFINPUT
- php file: plot.php
- <?php
- isset($_GET['fromYear']) ? $fromYear = $_GET['fromYear'] : $fromYear= gmdate("Y");
- isset($_GET['toYear']) ? $toYear = $_GET['toYear'] : $toYear = gmdate("Y");
- isset($_GET['fromMonth'])? $fromMonth = $_GET['fromMonth'] : $fromMonth= gmdate("m");
- isset($_GET['toMonth']) ? $toMonth = $_GET['toMonth'] : $toMonth = gmdate("m");
- isset($_GET['fromDay']) ? $fromDay = $_GET['fromDay'] : $fromDay = gmdate("d")-1;
- isset($_GET['toDay']) ? $toDay = $_GET['toDay'] : $toDay = gmdate("d")-1;
- isset($_GET['fromMin']) ? $fromMin = $_GET['fromMin'] : $fromMin = 0;
- isset($_GET['toMin']) ? $toMin = $_GET['toMin'] : $toMin = 0;
- isset($_GET['fromHour']) ? $fromHour = $_GET['fromHour'] : $fromHour= 0;
- isset($_GET['toHour']) ? $toHour = $_GET['toHour'] : $toHour = 23;
- isset($_GET['timeSlot']) ? $timeSlot = $_GET['timeSlot'] : $timeSlot= 60;
- isset($_GET['dataType']) ? $dataType = $_GET['dataType'] : $dataType= 0;
- $gap = $timeSlot;
- if ($dataType == 0)$coly = "nm_on";
- if ($dataType == 1)$coly = "nm_off";
- if($fromMonth<10)$fromMonth = "0".$fromMonth;
- if($toMonth<10) $toMonth = "0".$toMonth;
- if($fromDay<10) $fromDay = "0".$fromDay;
- if($toDay<10) $toDay = "0".$toDay;
- if($fromHour<10) $fromHour = "0".$fromHour;
- if($toHour<10) $toHour = "0".$toHour;
- if($fromMin<10) $fromMin = "0".$fromMin;
- if($toMin<10) $toMin = "0".$toMin;
- $from = $fromYear.$fromMonth.$fromDay.$fromHour.$fromMin."00";
- $to = $toYear.$toMonth.$toDay.$toHour.$toMin."60";
- passthru("/bin/bash plot ".escapeshellcmd($gap)." "
- .escapeshellcmd($from)." "
- .escapeshellcmd($to)." "
- .escapeshellcmd($coly));
- exit;
- ?>;
复制代码
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">;
|
|