[SOLVED] threshold on bar chart
It seems one can not add a threshold on a barchart.
Consider the following code:
Code:
/* Create and populate the pData object */
$MyData = new pData();
$MyData->addPoints(array(0.6,0.4),"frequences");
$MyData->setAxisName(0,"Fréquences");
/* Define the absissa serie */
$MyData->addPoints(array("service 1", "service 2")),"services");
$MyData->setSerieDescription("services","Services");
$MyData->setAbscissa("services");
/* Create the pChart object */
$myPicture = new pImage(700,230,$MyData);
/* Add a border to the picture */
$myPicture->drawRectangle(0,0,699,229,array("R"=>0,"G"=>0,"B"=>0));
/* Set the default font */
$myPicture->setFontProperties(array("FontName"=>"lib/pChart/fonts/verdana.ttf","FontSize"=>6));
/* Define the chart area */
$myPicture->setGraphArea(60,40,650,200);
/* Draw the scale */
$scaleSettings = array("GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE,"Mode"=>SCALE_MODE_START0);
$myPicture->drawScale($scaleSettings);
/* Draw the chart */
$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
$settings = array("Gradient"=>TRUE,"GradientMode"=>GRADIENT_EFFECT_CAN,"DisplayPos"=>LABEL_POS_INSIDE,"DisplayValues"=>TRUE,"DisplayR"=>255,"DisplayG"=>255,"DisplayB"=>255,"DisplayShadow"=>TRUE,"Surrounding"=>10);
$myPicture->drawBarChart();
$myPicture->drawThreshold(0.5,array("WriteCaption"=>true,"Caption"=>"Objectif","R"=>255,"G"=>0,"B"=>0));
the threshold is only drawn between the 2 bars (it would be drawn on a single point if the graph would have a single bar).
In order to have the threshold drawn correctly, You have to force margins in scale settings (it seems when there are no margins, getAbscissaMargin is not accurate)
Code:
/* Draw the scale */
$scaleSettings = array("GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE,"Mode"=>SCALE_MODE_START0,"XMargin"=>5,"YMargin"=>5);
$myPicture->drawScale($scaleSettings);
but when used this way, the bars are totally wrong
(both images are attached)
Is there a way to have a threshold on a bar chart?
Sorry, I later found the "NoMargin" option for threshold, that seems to be designed for the need i expressed