Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Nov 2012
    Posts
    33
    Thanks
    23
    Thanked 0 Times in 0 Posts

    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

  • #2
    New Coder
    Join Date
    Nov 2012
    Posts
    33
    Thanks
    23
    Thanked 0 Times in 0 Posts
    need ur help frnds...

  • #3
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    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.
    Last edited by AndrewGSW; 12-23-2012 at 04:26 PM.
    "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

  • Users who have thanked AndrewGSW for this post:

    ebookz (12-26-2012)

  • #4
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    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

  • Users who have thanked AndrewGSW for this post:

    ebookz (12-26-2012)

  • #5
    New Coder
    Join Date
    Nov 2012
    Posts
    33
    Thanks
    23
    Thanked 0 Times in 0 Posts

    Thumbs up

    tthanxx frnd..u all r doing great help for the upcoming new coders.....


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •