About Image_Graph Packge
| From: | Ji Park | Date: | Sun, 25 Jan 2009 00:25:01 +0000 |
| Subject: | About Image_Graph Packge | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-29638@lists.php.net to get a copy of this message | ||
Hello I having trouble with image_graph.
How do you dynamically create a graph with image_graph function by using
input fields to plot the minimum and maximum x coordinate ranges?
I am trying to generate a graph on a webpage with image_graph. In order to
make it more dynamic, I am also trying to add input fields for the users to
choose the minimum range and the maximum range for the domain of the graph.
I tried "echo"ing the <input> html right after calling done() function of
the image_graph, but it keeps crapping out displays the following error.
*Warning*: Cannot modify header information - headers already sent by
(output started at /var/www/cmp/index.php:17) in *
/usr/share/php/Image/Canvas.php* on line *644*
I've tried to put ob_start() function at the start of the php document but
it would just display the following:
The Image [...] could not be displayed because it contains errors.
here is my code:
[CODE]
<?php
require_once "Image/Graph.php";
/* set dataet variable */
$Dataset =& Image_Graph::factory('dataset');
/* Set the ranges for the x coordinate and the y coordinate */
$xrange = $_GET["xrange"];
$yrange = $_GET["yrange"];
/* Plot a parabolic graph */
for ($i = $xrange; $i <= $yrange; $i++) {
$ycoord = pow($i, 2);
$Dataset->addPoint($i, $ycoord);
}
echo "<form action=\"index.php\" method=\"post\">";
echo "<input type=\"text\" name=\"xrange\" />";
echo "<input type=\"text\" name=\"yrange\" />";
echo "<input type=\"submit\" />";
echo "</form>";
/* Initialize canvas for the graph */
$Graph =& Image_Graph::factory('graph', array(600, 400));
$Plotarea =& $Graph->addNew('plotarea');
/* Plot the data and set style attributes */
$Plot =& $Plotarea->addNew('line', array(&$Dataset));
$Plot->setLineColor('red');
/* Graph the thing */
$Graph->done();
?>
[/CODE]