A PHP Interface to GNUPlot
This is a simple PHP Interface to GNUPlot written by Liu Yi.
The main purpose of this program is to facilitate plotting with data
generated from program. It is not a *Complete* interface to GNU Plot.
The program itself is platform independent and it has been tested
under both Windows & Linux. But remember to set the location of GNU Plot
at the beginning of the program.
Feel free to drop me an email if you have suggestions or you have made
some changes which you think are useful.
HOW TO USE:
1) Set the location of GNU Plot
$GNUPLOT = 'C:\gnuplot\bin\pgnuplot.exe'; // for Windows
// $GNUPLOT = "gnuplot"; // for linux
2) Simply include the file in your program:
include('PHP_GnuPlot.php');
3) Initialize a process
$p = new GNUPlot();
4) Use methods provided in the class
function draw2DLine($x1,$y1, $x2, $y2)
function draw3DLine($x1,$y1,$z1, $x2, $y2,$z2)
function draw2DArrow($x1,$y1, $x2, $y2)
function draw3DArrow($x1,$y1,$z1, $x2, $y2,$z2)
function set2DLabel($labeltext, $x, $y, $justify='', $pre='', $extra='' )
function set3DLabel($labeltext, $x, $y, $z, $justify='', $pre='', $extra='' )
function setRange( $dimension, $min, $max, $extra='' )
function set( $toSet )
function setTitle( $title, $extra='' )
function setDimLabel( $dimension, $text, $extra='' )
function setTics( $dimension, $option )
function setSize( $x, $y, $extra )
function plotData( &$PGData, $method, $using, $axis='', $extra='' )
function splotData( &$PGData, $method, $using, $extra = '' )
function export( $pic_filename )
function reset()
function close()
And we have a way of doing low level call here:
function exe($command)
5) Check demo program for examples
[ Download the interface class ]
How do I plot a diagram with HUGE amount of data for each datagroup?
GNUplot may crash when we plot too many data points using the current "replot" strategy.
To avoid this problem, you can construct the command by yourself.
E.g.
Assume we have a variable $data that is an array of PGData
$command = 'plot ';
foreach($data as $c=>$v) {
if (!$data[$c]->filename) $data[$c]->dumpIntoFile();
if (!$data[$c]->filename) { print "Error: Empty dataset!\n"; return; }
$fn = $data[$c]->filename;
$title = $data[$c]->legend;
$command .= " '$fn' using 1:2 notitle with points,";
}
$p->exe( substr($command, 0, -1)."\n");
|