0

有没有办法使用 PHP 中的 pChart 库绘制 3D 条形图?

我可以绘制 3D 饼图,但不能绘制折线图。

我的代码如下所示

    //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");  
?><img src="generated/example12.png" />
4

1 回答 1

0

您需要对 drawStackedBarGraph 中的 pChart.class 或实际绘制部分中的 drawBarGraph 进行返工:

                          $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);

并添加一些 u-func:

function drawFilledPoly($points, $num, $r, $g, $b){
imagefilledpolygon  ($this->Picture ,  $points  , $num ,  $this->AllocateColor($this->Picture,$r,$g,$b));}
于 2010-07-26T09:57:33.887 回答