gregwar / gnuplot
GnuPlot library
Installs: 7 969
Dependents: 0
Suggesters: 0
Security: 0
Stars: 27
Watchers: 5
Forks: 12
Open Issues: 3
Requires
- php: >=5.3.0
This package is auto-updated.
Last update: 2024-12-13 15:06:28 UTC
README
A PHP Library for using GnuPlot
WARNING: This invoke the gnuplot
command line as back-end, which can lead to
arbitrary code execution. Be careful if you intend to use this library with
user-provided information. Have a look at this post for more information.
This is the output of the demo/write.php
:
Requirements
You need to have a server with gnuplot
installed and the safe mode
disabled (to be able to run proc_open()
)
Usage
There is examples in the demo/
directory.
You can create a graph and populate it like this:
<?php use Gregwar\GnuPlot\GnuPlot; $plot = new GnuPlot; // Setting the main graph title $plot->setGraphTitle('Demo graph'); // Adding three points to the first curve $plot ->setTitle(0, 'The first curve') ->push(0, 4) ->push(1, 5) ->push(2, 6) ; // Adding three points on the other curve // (with index 1) $plot ->setTitle(1, 'The first curve') ->push(0, 8, 1) ->push(1, 9, 1) ->push(2, 10, 2) ;
You can then save it to a file, have a look to write.php
for example:
<?php // Write the graph to out.png $plot->writePng('out.png');
Or render it directly into a browser, you can try out.php
for
example:
<?php header('Content-type: image/png'); echo $plot->get();
Or display it on the screen (useful with CLI scripts), run the
demo.php
script for example:
<?php $plot->display();
Or display it, and re-feed it in real time (with CLI scripts), you can
run realTime.php
for example:
<?php $plot->refresh();
API
push($x, $y, $index=0)
, add a point to the $index-nth curvedisplay()
, renders the graph on the screen (asuming you are using it as a CLI with an X Serverrefresh()
, same asdisplay()
, but will replot the graph after the first callget()
, gets the PNG data for your imagewritePng($filename)
, write the data to the output filesetTitle($index, $title)
, sets the title of the $index-nt curvesetGraphTitle($title)
, sets the main title for the graphsetXTimeFormat($format)
, sets the X axis as a time axis and specify data formatsetXTimeFormatString($format)
, specify the X axis time presentation formatsetXLabel($text)
, sets the label for the X axissetYLabel($text)
, sets the label for the Y axissetYFormat($format)
, sets Y axis formattingsetXRange($min, $max)
, set the X min & maxsetYRange($min, $max)
, set the Y min & maxsetWidth($width)
, sets the width of the graphsetHeight($height)
, sets the width of the graphaddLabel($x, $y, $text)
, add some label at a point
License
Gregwar\GnuPlot
is under MIT license