Multiple graphs with JPGraph
Posted: Mon Sep 24, 2007 7:46 am
I've been trying to generate multiple graphs using JPGraph, each to represent data for each month of the year.
I've been reading the documentation that JPGraph offers but the class doesn't seem to be generating a graph. The code has no syntax error nor does JP report any errors but nothing is returned to the browser.
I'm running a loop that runs 12 times, 1 for each month. This is the code I have at the moment, hopefully somebody can spot an error with the way I'm using JP. Having all the graphs in 1 images isn't really a concern, multiple images on 1 page would suit me better to be fair. I've tried looping 12 times through a standard bar chart but nothing is returned then either.
I realise I'm only adding graph1 & graph2 to the mgraph and there is 12 but I can't see how that would make a difference to JP being able to draw the graph so I didn't go to the bother of adding the other 10 graphs.
I've been reading the documentation that JPGraph offers but the class doesn't seem to be generating a graph. The code has no syntax error nor does JP report any errors but nothing is returned to the browser.
I'm running a loop that runs 12 times, 1 for each month. This is the code I have at the moment, hopefully somebody can spot an error with the way I'm using JP. Having all the graphs in 1 images isn't really a concern, multiple images on 1 page would suit me better to be fair. I've tried looping 12 times through a standard bar chart but nothing is returned then either.
Code: Select all
for($i = 1; $i <= 12; $i++) {
foreach($orders as $rName => $array) {
foreach($array as $month => $numOrders) {
$leg[] = $rName;
if($i == $month)
$data{$i}[] = $numOrders;
}
}
$graph{$i} = new Graph(1300,700);
$graph{$i}->SetScale("textlin");
$graph{$i}->SetFrame(false);
$graph{$i}->yaxis->title->Set("No. Orders");
$graph{$i}->title->Set("Graph");
$graph{$i}->xaxis->SetTickLabels($leg);
$graph{$i}->xaxis->SetLabelAngle(90);
$bplot{$i} = new BarPlot($data);
$bplot{$i}->SetFillColor("blue");
$bplot{$i}->value->SetFormat('%d');
$bplot{$i}->value->Show();
}
$mgraph = new MGraph();
$xpos1=3;$ypos1=3;
$xpos2=3;$ypos2=200;
$mgraph->Add($graph1,$leg,$data);
$mgraph->Add($graph2,$leg,$data);
$mgraph->Stroke();