PCHomepage
Programmer
I have a JPGraph line plot inside a function and have showed below only the portions in question. The plot is working in pulling up multiple columns of data but I can't seem to get the legend to show properly, especially as there is also a sub form to selest what to graph. By default, all four columns are graphed, then there are checkboxes to pick more specifics. As it is, it shows all properly or I can pick only one at a time without a JPGraph crash (any two or more crashes it) but the main problem is in the legend, which has to get a title from a database table, shows all the titles for each column and it's obvious why but I'm not sure what to do about it! It's also showing all the same title so if two are being graphed, and there are four columns of data, I see the same file name eight times and it does not show the mark type.
I would also like it to show the column name at the peak of each graph.
Can anyone help?
I would also like it to show the column name at the peak of each graph.
Can anyone help?
Code:
if ($result = $mysqli->query("$Query")) :
while ($row = $result->fetch_array()) :
$datax[$row[0]][] = $row[1];
$datay1[$row[0]][] = $row[2];
$datay2[$row[0]][] = $row[3];
$datay3[$row[0]][] = $row[4];
$datay4[$row[0]][] = $row[5];
endwhile;
$result->close();
else:
echo "<div class=\"Message\">\n";
printf("MySQLi Error: %s\n", $mysqli->error);
echo "</div>\n\n";
endif;
foreach($datay1 as $key=>$_datay): // for Legend
$queryFN = "SELECT FileName FROM dcs_uploads ";
$queryFN .= "WHERE ID = ".$key." ";
$queryFN .= "ORDER by FileName";
if ($result = $mysqli->query($queryFN)):
$row = $result->fetch_row();
$FileName = $row[0];
endif;
endforeach;
if (!$SubData || $SubData == 'Red'):
foreach($datay1 as $key=>$_datay): // for Red
$lp[$key] = new LinePlot($_datay,$datax[$key]);
$graph->Add($lp[$key]);
$lp[$key]->mark->SetType(MARK_DIAMOND, 'red', 0.3);
$lp[$key] = new LinePlot($_datay,$datax[$key]);
$graph->Add($lp[$key]);
$lp[$key]->SetLegend(basename($FileName, ".csv"));
endforeach;
endif;
if (!$SubData || $SubData == 'Gr'):
foreach($datay2 as $key=>$_datay): // for Gr
$lp[$key] = new LinePlot($_datay,$datax[$key]);
$graph->Add($lp[$key]);
$lp[$key]->mark->SetType(MARK_UTRIANGLE, 'green', 0.3);
$lp[$key] = new LinePlot($_datay,$datax[$key]);
$graph->Add($lp[$key]);
$lp[$key]->SetLegend(basename($FileName, ".csv"));
endforeach;
endif;
if (!$SubData || $SubData == 'Gb'):
foreach($datay3 as $key=>$_datay): // for Gb
$lp[$key] = new LinePlot($_datay,$datax[$key]);
$graph->Add($lp[$key]);
$lp[$key]->mark->SetType(MARK_DTRIANGLE, 'teal', 0.3);
$lp[$key] = new LinePlot($_datay,$datax[$key]);
$graph->Add($lp[$key]);
$lp[$key]->SetLegend(basename($FileName, ".csv"));
endforeach;
endif;
if (!$SubData || $SubData == 'B'):
foreach($datay4 as $key=>$_datay): // for B
$lp[$key] = new LinePlot($_datay,$datax[$key]);
$graph->Add($lp[$key]);
$lp[$key]->mark->SetType(MARK_SQUARE, 'blue', 0.3);
$lp[$key] = new LinePlot($_datay,$datax[$key]);
$graph->Add($lp[$key]);
$lp[$key]->SetLegend(basename($FileName, ".csv"));
endforeach;
endif;