How to change the Legend box color in bar chart

Hai all,

      I am working in JPgraphs. But one problem is in my program. I submit my code as below.

code:

[php]<?php
include ("…/jpgraph.php");
include ("…/jpgraph_bar.php");
include ("…/jpgraph_log.php");
$con = mysql_connect(“localhost”,"","");
$db = mysql_select_db(“helpdesk”,$con)or die(mysql_error());
$sql = “SELECT sum(Helpdesk_Project_Timesheet_Projectduration) as sum,Helpdesk_Project_Timesheet_Traineename as name FROM Helpdesk_Project_Timesheet GROUP BY Helpdesk_Project_Timesheet_Traineename”;
$res = mysql_query($sql)or die(mysql_error());

while($row = mysql_fetch_array($res))
{

$name[] = $row[‘name’];
$total = $row[‘sum’];
$tot = explode(".",$total);//Split the $total values
$durh = $tot[0];
$durm = $tot[1];
$du = $durh.".".$durm;

//Selected Table values to store in Array
$k[] = $du;
$g =$name;//Fetch the Staff names

}

// Create the graph. These two calls are always required
$graph = new Graph(650,460,“auto”);
$graph->SetScale(“textlog”);
// Get localised version of the staff names
$graph->xaxis->SetTickLabels($g);

//
//$graph->SetTickDensity(TICKD_DENSE);

$graph->SetShadow();
$graph->img->SetMargin(60,20,30,140);

// Create the bar plots
$data = $k;//Fetch the totalhours values
$staff =$g;
$colorval=array(‘green’,‘blue’,‘orange’,‘brown’,‘cyan’,‘darkmagenta’,‘goldenrod’,‘lightsalmon’,‘maroon’);

for($c=0;$c<count($g);$c++)
{

$bplot[$c] = new BarPlot($data);
$bplot[$c]->value->show();
$bplot[$c]->SetWidth(0.2);
$bplot[$c]->SetFillColor($colorval);
$bplot[$c]->SetLegend($staff[$c]);

// …and add it to the Graph
$graph->Add($bplot[$c]);

}

//Set X,Y axis and Graph Title
$graph->title->Set(“Staff performance”);
$graph->xaxis->title->Set(“Staff”);
$graph->yaxis->title->Set(“Total working Hours”);
//Set Graph and X,Y axis Title Fonts and Color
$graph->title->SetFont(FF_FONT2,FS_BOLD);
$graph->title->SetColor(‘orange’);
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->yaxis->title->SetColor(‘red’);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetColor(‘blue’);

//Set Legend Position and Font
$graph->legend->SetFont(FF_FONT1,FS_NORMAL);
$graph->legend->Pos(0.7,0.7,‘bottom’,‘left’);

// Display the graph
$graph->Stroke();

?>[/php]

The program is working fine. but legend rectangle box color will not be change in different color.It will filled first color in all the boxs. So, how to solve this problem. please urgent anybody help for me…
Regards,
Mohamed.

**Mod Edit - Added PHP tags for better readability.

Unless I don’t understand what you are asking, I see you pull all the colors out and put them into an array called $color[]. But I never see you reference it again in code. You need to use after you create it, all I see is hard coded colors.

Sponsor our Newsletter | Privacy Policy | Terms of Service