Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-23-2012, 05:01 AM   PM User | #1
ebookz
New Coder

 
Join Date: Nov 2012
Posts: 33
Thanks: 23
Thanked 0 Times in 0 Posts
ebookz is an unknown quantity at this point
Question Jpgraph : how set label for group bar column chart in php

here is the sample jpgraph code:
Code:
<?php 
require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_bar.php');

$datay1=array(35,160,0,0,0,0);
$datay2=array(35,190,190,190,190,190);
$datay3=array(20,70,70,140,230,260);

$graph = new Graph(450,200,'auto');    
$graph->SetScale("textlin");
$graph->SetShadow();
$graph->img->SetMargin(40,30,40,40);
$graph->xaxis->SetTickLabels($gDateLocale->GetShortMonth());

$graph->xaxis->title->Set('Year 2002');
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);

$graph->title->Set('Group bar plot');
$graph->title->SetFont(FF_FONT1,FS_BOLD);

$bplot1 = new BarPlot($datay1);
$bplot2 = new BarPlot($datay2);
$bplot3 = new BarPlot($datay3);

$bplot1->SetFillColor("orange");
$bplot2->SetFillColor("brown");
$bplot3->SetFillColor("darkgreen");

$gbarplot = new GroupBarPlot(array($bplot1,$bplot2,$bplot3));
$gbarplot->SetWidth(0.6);
$graph->Add($gbarplot);

$graph->Stroke();
?>
this code has no error and this is working perfectly... ...out put of this code is see the img:

my problem is how can I set labels for this multi bars for identifying themHow can I set A LABELS LIKE this:

then I need fINAL OUT PUT LIKE THIS :

I USED THIS below CODE BUT IT doesn't work for me....
Code:
$graph->SetLegends(array('Pass','Fail','Not Eligble')); $graph->Add($p1);
How can I do it???????please help me frnds...thankssss
ebookz is offline   Reply With Quote
Old 12-23-2012, 07:18 AM   PM User | #2
ebookz
New Coder

 
Join Date: Nov 2012
Posts: 33
Thanks: 23
Thanked 0 Times in 0 Posts
ebookz is an unknown quantity at this point
need ur help frnds...
ebookz is offline   Reply With Quote
Old 12-23-2012, 03:16 PM   PM User | #3
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
A quick Google tells me that SetLegends is for a pie chart. I think you need to set the legends individually as the chart is created, from this code I found:
PHP Code:
for ($i=0$i $tg$i++) {                  // total groups 
  
$bplot[$i] = new BarPlot($datay[$i]); 
  
$bplot[$i]->SetFillColor($color[$i]); 
  
$bplot[$i]->SetLegend($groupU[$i]); 

$gbarplot = new GroupBarPlot($bplot); 
This page seems to contain all the information you might need [The wonders of Google ].

Then this page tells you how to position and customize the legend.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS

Last edited by AndrewGSW; 12-23-2012 at 03:26 PM..
AndrewGSW is offline   Reply With Quote
Users who have thanked AndrewGSW for this post:
ebookz (12-26-2012)
Old 12-23-2012, 04:26 PM   PM User | #4
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
PHP Code:
$bplot1->SetFillColor("orange");
$bplot2->SetFillColor("brown");
$bplot3->SetFillColor("darkgreen");

$bplot1->SetLegend("Pass");
$bplot2->SetLegend("Fail");
$bplot3->SetLegend("NotEligible")

$gbarplot = new GroupBarPlot(array($bplot1,$bplot2,$bplot3));
$gbarplot->SetWidth(0.6);
$graph->Add($gbarplot);

$graph->Stroke(); 
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Users who have thanked AndrewGSW for this post:
ebookz (12-26-2012)
Old 12-26-2012, 03:05 AM   PM User | #5
ebookz
New Coder

 
Join Date: Nov 2012
Posts: 33
Thanks: 23
Thanked 0 Times in 0 Posts
ebookz is an unknown quantity at this point
Thumbs up

tthanxx frnd..u all r doing great help for the upcoming new coders.....
ebookz is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:48 AM.


Advertisement
Log in to turn off these ads.