我正在尝试使用pChart创建一个使用3系列的组合图表。两个系列用于堆叠条形,其余系列用于条形图。我想要实现的是在侧面放置带有常规条的堆叠条柱(如总条)。有没有办法实现这个目标? 我知道pChart可以选择组合图表,但它似乎只有在组合不同类型的图表时才能工作,例如bar和line。但是,当我尝试组合类似的图形,如条形图和堆积条形图时,它们似乎相互覆盖。 pChart文档在这个主题上不是很清楚(或者我真的错过了那里的东西)。 我的代码:
$MyData = new pData();
$Mydata->addPoints(array(0,97,149,167),"Previous");
$Mydata->addPoints(array(97,52,18,10),"Current");
$Mydata->addPoints(array(97,149,167,177),"Total");
$Mydata->setAxisName(0,"Quantity");
$Mydata->addPoints(array('1','2','3','4'),"Period");
$Mydata->setSerieDescription("Period","Period");
$Mydata->setAbscissa("Period");
$Mydata->setAbscissaName("Period");
$MyChart = new pImage(975,520,$MyData);
$MyChart->setFontProperties(array("FontName"=>"pChart/fonts/verdana.ttf","FontSize"=>11));
$MyChart->setGraphArea(270,100,940,390);
$MyChart->drawFilledRectangle(270,100,940,390,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10));
$MyChart->drawScale(array('CycleBackground'=>TRUE,'Mode'=>SCALE_MODE_START0,'Factors'=>array(20),"Pos"=>SCALE_POS_TOPBOTTOM,"DrawSubTicks"=>FALSE,"GridR"=>128,"GridG"=>128,"GridB"=>128,"GridAlpha"=>20));
$MyChart->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
$MyChart->setFontProperties(array("FontName"=>"pChart/fonts/verdana.ttf","FontSize"=>11));
$MyData->setSerieDrawable("Total",FALSE);
$MyChart->drawStackedBarChart(array("DisplayValues"=>TRUE,"DisplayColor"=>DISPLAY_AUTO,"Rounded"=>TRUE,"Surrounding"=>60));
$MyData->setSerieDrawable("Previous",FALSE);
$MyData->setSerieDrawable("Current",FALSE);
$MyData->setSerieDrawable("Total",TRUE);
$MyChart->drawBarChart(array("DisplayPos"=>LABEL_POS_INSIDE,"DisplayValues"=>TRUE,"DisplayColor"=>DISPLAY_AUTO,"Rounded"=>TRUE,"Surrounding"=>60));
$MyChart->setShadow(FALSE);
$MyData->setSerieDrawable("Previous",TRUE);
$MyData->setSerieDrawable("Current",TRUE);
$MyChart->drawLegend(30,20,array("Alpha"=>20,"Mode"=>LEGEND_VERTICAL));
$MyChart->Render("Graph.png");
感谢您的帮助。
答案 0 :(得分:0)
代码段..
#$MyData->setSerieDrawable("Received",true);
#$MyData->setSerieDrawable("Despatched",true);
# pData::setSerieDrawable does not work in PHP 5.2.6, it might work in later versions but my OOP knowledge is limited
# Previously in this script $myPicture = new pImage($imgW,400,$MyData); is called with an instance of $MyData
# this is added to by pImage I think
# the problem is that #$MyData->setSerieDrawable("Despatched",true); affects $MyData and not the data in pImage
#
# my solution was to add a new function in pImage
#
# function SetisDrawable($SerieName='', $isDrawable=false) {
# if(!empty($SerieName)){
# $this->DataSet->Data["Series"][$SerieName]["isDrawable"] = $isDrawable;
# }
# }
#
$myPicture->SetisDrawable("Received", FALSE);
$myPicture->SetisDrawable("Despatched", FALSE);
$myPicture->SetisDrawable("WIP", TRUE);
$myPicture->drawLineChart(array("DisplayValues"=>TRUE, "DisplayOffset"=>"15"));
#Regards, Chris Bowker