I posted this on the jpgraph forum, but there seem to be a lot more active folks here....
Problem: I do a MySQL query that gives me a multidimensional array:
ie. "$CHARTSCORES"
which includes the "fields"
STUDENTNAME
TESTPHASE
SCORE
I want to create a (multiple, jpgraph) barplot that show's each student's name along the bottom and the N number of TESTPHASE SCORES all grouped together (ie. Fall, Winter, Spring). The problem is, I often encounter a variable number of TESTPHASES for data that is being kept. If I can specify the TESTPHASES ahead of time, it's no problem to build the graph. I can just do something like this...
......
while ($Row=mysql_fetch_array($Result)) {
$datax[] = "$Row[STUDENTNAME] ";
$dataFALL[] = $Row[SCORE];
$dataWINTER[] = $Row[SCORE];
$dataSPRING[] = $Row[SCORE];
}
.....
// Create the 3 bar plots
$b1plot = new BarPlot($data1y);
$b2plot = new BarPlot($data2y);
$b3plot = new BarPlot($data3y);
// Create the grouped bar plot
$gbplot = new GroupBarPlot(array($b1plot,$b2plot,$b3plot));
// ...and add it to the graph
$graph->Add($gbplot);
All that works fine.
But when I don't know ahead of time how frequently the kids were tested and/or how the testphase was tagged (maybe with a month name instead of a season code, etc.) it seems I have to create N "dataY" arrays on the fly with some sort of loop.
If the values in the multidimensional arrays $CHARTSCORES can be addressed like so:
$CHARTSCORES[STUDENTNAME][TESTPHASE] => SCORE
I imagine I need a FOREACH loop that will build me N unique bplot? names to correspond with N unique dataY? arrays name for each TESTPHASE it encounters, and then plop the STUDENTNAME and SCORE data into them.
That's where I'm stuck.