'Problem displaying zero values in bar chart
I'm having trouble displaying zero values on pChart-driven bar charts. The zero-value bar turns into a large triangular shape that extends across the entire chart.
Zero values seem to be the only problem.
Any help would be appreciated.
Here's my code:
function createScoreChart($data,$filename,$title) {
$myData = new Data();
for($i=0;$i<105;$i=$i+5) {
if($data[$i]) {
$myData->addPoints($data[$i],"Scores");
if($data[$i] > $maxQuantity) {
$maxQuantity = $data[$i];
}
}
else {
$myData->addPoints('VOID',"Scores");
}
}
/* Set line weight */
$myData->setSerieWeight("Scores",1);
$serieSettings = array("R"=>87,"G"=>135,"B"=>178,"Alpha"=>100);
$myData->setPalette("Scores",$serieSettings);
/* Create labels */
for($i=0;$i<105;$i=$i+5) {
$myData->addPoints($i . '%',"Labels");
}
$myData->setAbscissa("Labels");
$myData->setAxisPosition(0,AXIS_POSITION_LEFT);
/* Create the pChart object */
$myPicture = new Image(800,400,$myData);
/* Draw a solid background */
$myPicture->drawFilledRectangle(0, 0, 799, 399, [
"R" => 247,
"G" => 247,
"B" => 247
]);
/* Add a border to the picture */
$myPicture->drawRectangle(0,0,799,399);
/* Write the picture title */
$myPicture->setFontProperties(array("FontName"=>$_SERVER['DOCUMENT_ROOT'] . "/admin/includes/verdana-bold.ttf","FontSize"=>16));
$myPicture->drawText(400,35,$title, array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE));
/* Set the default font properties */
$myPicture->setFontProperties(array("FontName"=>$_SERVER['DOCUMENT_ROOT'] . "/admin/includes/verdana.ttf","FontSize"=>9));
/* Draw the chart scale */
$myPicture->setGraphArea(40,50,760,360);
$AxisBoundaries = array(0=>array("Min"=>0,"Max"=>$maxQuantity));
$ScaleSettings = array("Mode"=>SCALE_MODE_MANUAL,"ManualScale"=>$AxisBoundaries,"DrawSubTicks"=>TRUE,"DrawArrows"=>FALSE,"ArrowSize"=>0);
$myPicture->drawScale($ScaleSettings);
/* Draw the scale, keep everything automatic */
$myPicture->drawFilledStepChart(array("DisplayColor"=>'#000000'));
/* Save the picture to server */
$myPicture->Render($_SERVER['DOCUMENT_ROOT'] . '/admin/tmp/' . $filename);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
