tags:

views:

362

answers:

2

Is there a way to draw a 3D Bar Graph using the pChart library in PHP?

I'm able to draw a 3D Pie graph but not a line graph.

Any help would be appreciated.

My code looks as follows

//The 3D bar graph
# // Dataset definition   
$DataSet = new pData;

// $DataSet->AddPoint(array(10,40,30,20,30,30,20,10,10,70,40),"Serie1");
$DataSet->AddPoint(52,"Serie2","January 2009"); $DataSet->AddPoint(94,"Serie2","February 2009"); $DataSet->AddPoint(44,"Serie2","March 2009"); $DataSet->AddPoint(65,"Serie2","April 2009"); $DataSet->AddPoint(38,"Serie2","May 2009"); $DataSet->AddPoint(43,"Serie2","August 2009"); $DataSet->AddPoint(34,"Serie2","September 2009");

$DataSet->AddAllSeries();  
$DataSet->SetAbsciseLabelSerie();  
$DataSet->SetSerieName("Months","Serie2");
//$DataSet->SetXAxisFormat("date");

// $DataSet->SetXAxisUnit("months");

// Initialise the graph  
$Test = new pChart(800,240);
$Test->setFixedScale(0,100); 
$Test->loadColorPalette('pChart.1.26e/color/tones-4.txt',',');
$Test->setFontProperties("pChart.1.26e/Fonts/FreeSans.ttf",8);  
$Test->setGraphArea(50,30,680,200);  
$Test->drawFilledRoundedRectangle(7,7,693,223,5,255,255,255);  
$Test->drawRectangle(10,5,695,225,169,169,169);  
$Test->drawGraphArea(255,255,255,TRUE);  
$Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),10,150,150,150,TRUE,0,2,TRUE);     
$Test->drawGrid(10,TRUE,230,230,230,50);  

$Test->setFontProperties("pChart.1.26e/Fonts/FreeSansBold.ttf",15);  
$Test->drawTitle(50,22,"Clicks Per Month",50,50,50,585);  

// Draw the 0 line  
$Test->setFontProperties("pChart.1.26e/Fonts/FreeSans.ttf",6);  
$Test->drawTreshold(0,143,55,72,TRUE,TRUE);

//Monthly Target
$Test->setFontProperties("pChart.1.26e/Fonts/FreeSansBold.ttf",10);
$Test->drawTreshold(40,143,55,72,TRUE,TRUE,4);


// Draw the bar graph  
$Test->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE);  
// Finish the graph  
$Test->setFontProperties("pChart.1.26e/Fonts/FreeSans.ttf",8);

// $Test->drawLegend(596,150,$DataSet->GetDataDescription(),255,255,255);

$Test->Render("generated/example12.png");

?>

A: 

can you please explain what is this example12.png, do i need to pass an already created png file or it will be generated itself?? if I need a png file beforehand, where should i keep it then?

ashish khurana
the script creates that file, you do not need it beforehand
Roland
A: 

youll need a rework for a pChart.class in drawStackedBarGraph or drawBarGraph in actually-draw part:

                          $this->drawFilledRectangle($XPos+1,$YBottom,$XPos+$SeriesWidth-11,$YPos,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE,$Alpha);
        //right
        $colorEnh=50; 
         $this->drawFilledPoly(array(
          $XPos+$SeriesWidth-10, $YBottom,
          $XPos+$SeriesWidth-10, $YPos,
          $XPos+$SeriesWidth-1, $YPos-10,
          $XPos+$SeriesWidth-1, $YBottom-10,
          ), 4, $this->Palette[$ColorID]["R"]+$colorEnh,$this->Palette[$ColorID]["G"]+$colorEnh,$this->Palette[$ColorID]["B"]+$colorEnh);
         //top
         $this->drawFilledPoly(array(
          $XPos+1, $YPos,
          $XPos+10+1, $YPos-10,
          $XPos+$SeriesWidth-1, $YPos-10,
          $XPos+$SeriesWidth-10-1, $YPos,
          ), 4, $this->Palette[$ColorID]["R"]-$colorEnh,$this->Palette[$ColorID]["G"]-$colorEnh,$this->Palette[$ColorID]["B"]-$colorEnh);

and add some u-func:

function drawFilledPoly($points, $num, $r, $g, $b){
imagefilledpolygon  ($this->Picture ,  $points  , $num ,  $this->AllocateColor($this->Picture,$r,$g,$b));}