Forum Moderators: coopster
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>
----------------------------------------
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]
?>