Forum Moderators: coopster

Message Too Old, No Replies

Including a PHP Generated Graph

Can I put it on the same php page somehow?

         

rover

1:54 am on Feb 22, 2005 (gmt 0)

10+ Year Member



Hi-

I'm using a php script to generate graphs. Somehow, I'm trying to get it so that the script will be able to be displayed on the same graph.php page on which the graph data is first generated. The problem is that the script designates an image/png header, so I get the error:

Warning: Cannot modify header information - headers already sent

Does anyone know if there is any way to get around this so that the graph can be displayed on the same page?

The graph.php page basically looks something like:

----------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Graph Page</TITLE>
</HEAD>
<BODY>

...Various HTML & PHP bits included here...

Then the PHP code to generate the graph:

<?php

Header("Content-Type: image/png");
require("./chartmaker.php");

$vCht4 = array(60,40,20,34,5,52,41,20,34,43,64,40);
$vCht5 = array(12,21,36,27,14,23,3,5,29,23,12,5);
$vCht6 = array(5,7,3,15,7,8,2,2,2,11,22,3);
$vLabels = array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');

$ochart = new chart(500,250,5, '#eeeeee');
$ochart->setTitle("Graph Title","#000000",5);
$ochart->setPlotArea(SOLID,"#888888", '#dddddd');
$ochart->setFormat(0,',','.');
$ochart->addSeries($vCht4,'impuls','Series1', SOLID,'#000000', '#0000ff');
$ochart->setXAxis('#000000', SOLID, 5, "X Axis");
$ochart->setYAxis('#000000', SOLID, 2, "Y Axis");
$ochart->setLabels($vLabels, '#000000', 3, VERTICAL);
$ochart->setGrid("#bbbbbb", DASHED, "#bbbbbb", DOTTED);
$ochart->plot('');
?>

</BODY>

</HTML>

----------------------------------------

Elijah

3:05 am on Feb 22, 2005 (gmt 0)

10+ Year Member



Here's an idea:

Try replacing the php code you have with this:


<?php
[b]echo '<img src="'.$_SERVER['PHP_SELF'],'?return_graph=1">';
if (FALSE == empty($_GET['return_graph'])) {[/b]
Header("Content-Type: image/png");
require("./chartmaker.php");

$vCht4 = array(60,40,20,34,5,52,41,20,34,43,64,40);
$vCht5 = array(12,21,36,27,14,23,3,5,29,23,12,5);
$vCht6 = array(5,7,3,15,7,8,2,2,2,11,22,3);
$vLabels = array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');

$ochart = new chart(500,250,5, '#eeeeee');
$ochart->setTitle("Graph Title","#000000",5);
$ochart->setPlotArea(SOLID,"#888888", '#dddddd');
$ochart->setFormat(0,',','.');
$ochart->addSeries($vCht4,'impuls','Series1', SOLID,'#000000', '#0000ff');
$ochart->setXAxis('#000000', SOLID, 5, "X Axis");
$ochart->setYAxis('#000000', SOLID, 2, "Y Axis");
$ochart->setLabels($vLabels, '#000000', 3, VERTICAL);
$ochart->setGrid("#bbbbbb", DASHED, "#bbbbbb", DOTTED);
$ochart->plot('');
[b]}[/b]
?>

badone

7:09 am on Feb 22, 2005 (gmt 0)

10+ Year Member



Put the code to generate the graph into graphgen.php and call it from graph.php like this;

<img src='graphgen.php?colour=".$colour."'>

insert your own variable list.

Cheers,
BAD

rover

7:59 pm on Feb 22, 2005 (gmt 0)

10+ Year Member



Thanks very much. I tried Elijah's, but unfortunately it showed a broken image. The other solution would still require me to have the specifications for the graph on another file, so that wouldn't work for me (unless I misunderstood it somehow).

badone

12:21 am on Feb 23, 2005 (gmt 0)

10+ Year Member



Can't you pass the specifications for the graph as variables to the graphgen.php?

Example;

print "<img src='graphgen.php?colour=".$colour."&scale=".$scale."&speed=".$speed."&time=".$time."'>"