PCHomepage
Programmer
I've searched everywhere but cannot find any reference to show how to add a second label to a simple vertical JPGraph bar graph. Currently the X labels are coming from the X-value of the database and they need to remain but there is also a file name descriptor that is too long to put there so I need it on or next to the bar. The data is referenced as:
Should FileName be $FileName or $FileName[]?
Also, when I enable the legend, it shows only a single item when there should be several. Below is the code for main portion of the graph in case it's needed to answer the question:
Code:
if ($result = $mysqli->query("$PlotWhat")):
while ($row = $result->fetch_array()):
$FileName[COLOR=red][][/color] = $row[0];
$datay[] = $row[1];
$datax[] = $row[2];
endwhile;
$result->close();
else:
echo "<div class=\"Message\">\n";
printf("MySQLi Error: %s\n", $mysqli->error);
echo "</div>\n\n";
endif;
Should FileName be $FileName or $FileName[]?
Also, when I enable the legend, it shows only a single item when there should be several. Below is the code for main portion of the graph in case it's needed to answer the question:
Code:
require_once ($JPGraphPath."/jpgraph.php");
require_once ($JPGraphPath."/jpgraph_bar.php");
require_once ($JPGraphPath."/jpgraph_log.php");
$graph = new Graph(800,450);
$graph->SetImgFormat('png',60);
$graph->SetScale('textlin');
$graph->img->SetMargin(100,40,40,75);
$graph->SetShadow();
$ReplaceVals = array("ID", "s", "d");
$ReplaceWith = array(" ID", "S", "D");
$graph->title->Set($PlotName." vs ".str_replace($ReplaceVals, $ReplaceWith, $PlotNameX));
$graph->title->SetFont(FF_ARIAL,FS_BOLD,12);
// Set Y-Axis appearance
$pieces = explodeForce("_", $PlotName, 2);
$YName = $pieces[0];
if (!stristr($YName,"peak")):
$graph->yaxis->title->Set($YName." ".$DataType);
else:
$graph->yaxis->title->Set(str_replace("_", " ", $PlotName)." ".$DataType.$FileName);
endif;
$graph->yaxis->title->SetFont(FF_ARIAL,FS_BOLD,10);
$graph->yaxis->title->SetMargin(50);
$graph->yaxis->scale->SetGrace(10);
// Set X-Axis title
$graph->xaxis->SetTitle("",'middle');
$graph->xaxis->scale->ticks->Set(40,20);
$graph->xaxis->title->SetFont(FF_ARIAL,FS_BOLD,10);
$graph->xaxis->title->SetMargin(20);
$graph->xaxis->SetLabelAngle(90);
if ($PlotNameX == 'date') $graph->xaxis->SetTickLabels(str_replace(".","-", $datax));
if ($PlotNameX != 'date') $graph->xaxis->SetTickLabels($datax);
$graph->xaxis->SetLabelMargin(2);
$graph->xaxis->scale->SetGrace(0,0);
$graph->ygrid->Show(true,true);
$graph->xgrid->Show(true,false);
$bplot = new BarPlot($datay);
$bplot->SetAlign('center');
$graph->Add($bplot);
$bplot->SetYBase(0);
if (!$Weight) $bplot->SetAbsWidth(10);
if ($Weight) $bplot->SetAbsWidth(30);
$bplot->SetFillColor('#B0E0E6');
if ($Fill) $bplot->SetFillGradient('#B0E0E6:0.7', '#B0E0E6:1.2', GRAD_VER);
$bplot->SetShadow();
$bplot->value->Show();
$bplot->SetValuePos('top');
$bplot->value->SetFont(FF_ARIAL,FS_BOLD,10);
if (!$Weight) $bplot->value->SetAngle(45);
if ($Weight) $bplot->value->SetAngle(0);
$bplot->value->SetFormat('%0.1f');
if ($Legend) $bplot->SetLegend(trim(basename($FileName, ".csv")));