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.


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”);
// Get localised version of the staff names



// Create the bar plots
$data = $k;//Fetch the totalhours values
$staff =$g;


$bplot[$c] = new BarPlot($data);

// …and add it to the Graph


//Set X,Y axis and Graph Title
$graph->title->Set(“Staff performance”);
$graph->yaxis->title->Set(“Total working Hours”);
//Set Graph and X,Y axis Title Fonts and Color

//Set Legend Position and Font

// Display the graph


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…

**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