I'm trying to dynamically create a bar graph where I am getting a set of historical data, comparing 4 groups for the past 12 months. Right now, I only have 3 months of data, but that doesn't really matter. Anyway, I have generated two "cousins" a line graph and side by side single graphs comparing each group. The error message I get is this:
One of the objects submitted to GroupBar is not a BarPlot. Make sure that you created the Group Bar plot from an array of BarPlot or AccBarPlot objects. (Class = )
This tells me I'm doing something wrong with my array. My code looks like this:
<?php
include("jpgraph/src/jpgraph.php");
include("jpgraph/src/jpgraph_bar.php");
// Create the basic graph
$graph = new Graph(750, 500,"auto");
$graph->SetScale("textlin");
$graph->img->SetMargin(40,80,30,40);
// set color- code remove - irrelevant
// Get the data
$st = $_GET['start'];
$tg = $_GET['total_group'];
for ($i=0; $i < $tg; $i++) {
$grup = "grp_".$i;
$groupL[$i] = $_GET[$grup];
$groupU[$i] = strtoupper($_GET[$grup]);
}
$tm = $_GET['total_month'];
for ($i=$st; $i < $tm; $i++) {
$m = "m".$i;
$mm[$i] = $_GET[$m];
$j = $i - $st;
$month[$j] = $_GET[$m];
}
for ($i=0; $i < $tg; $i++) { // total groups
for ($m=$st; $m < $tm; $m++) { // total months
$groupV = $groupL[$i]."_".$m;
$j = $m - $st;
$datay[$i][$j] = $_GET[$groupV];
}
}
// Adjust the position of the legend box
$graph->legend->Pos(0.02,0.15);
// Adjust the color for theshadow of the legend - code remove - irrelevant
// Set axis titles and fonts - code remove - irrelevant
for ($i=0; $i < $tg; $i++) { // total groups
$bplot[$i] = new BarPlot($datay[$i]);
$bplot[$i]->SetFillColor($color[$i]);
$bplot[$i]->SetLegend($groupU[$i]); // Set the legends for the plots
}
$gbarplot = new GroupBarPlot(array($bplot));
$gbarplot->SetWidth(0.4);
$graph->Add($gbarplot);
$graph->Stroke();
?>
I figure it's something in the way I'm handling $bplot, but I'm not exactly sure what to do there. Any suggestions? Oh, btw, my input line looks like this:
<img src="all_bar.php?grp_0=mgroup&grp_1=kgroup&grp_2=jgroup&grp_3=ggroup
&mgroup_0=421&mgroup_1=385&mgroup_2=606
&kgroup_0=279&&kgroup_1=579&kgroup_2=170
&jgroup_0=272&jgroup_1=262&jgroup_2=150
&ggroup_0=409&ggroup_1=489&ggroup_2=682
&m0=Jul&m1=Aug&m2=Sep
&total_month=3&total_group=4&start=0" />