Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Second Label on Vertical Bar Graph

Status
Not open for further replies.

PCHomepage

Programmer
Feb 24, 2009
609
US
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:

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")));
 
No luck at all on adding the label but on the legend, I was able to get all to show but only one in the muddle has the color box. Even though they'll all be the same, it would look better if all had it or if none did! $Legend is simply a value from a checkbox that allows the legend to be enabled or disabled at will. Without the char(10) it was all on a single row. Any ideas on getting this to work better?

Code:
$LegeNames = implode(chr(10), $FileName);
if ($Legend) $bplot->SetLegend($LegeNames);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top