pChart 2.x graph plots scale using decimals instead of whole numbers
I'm working on stats containing a number of visits and the scale on pChart is showing decimals instead of whole integers.
The default setting is creating scales with fractions similar to below:
0 0.2 0.4 0.6 0.8 1.0 1.2 |=== |======== |============================ |=== |===================
That doesn't work as you can't visit a site 1.2 times.
I was trying to make scale only with whole numbers (0, 1, 2 etc.) with "Mode"=>SCALE_MODE_MANUAL
parameter but I failed.
How do I set or force pChart to plot using whole numbers on the axi开发者_JAVA技巧s?
You are possibly best to adjust your data, rather than your graph, as you will still see the bar chart showing 1.2, even if the scale says 1.
If you were still trying to fix the axis boundaries, you set the axis boundaries, and use the minimum div height value, you can have better control over your axis.
$AxisBoundaries = array(0=>array("Min"=>0,"Max"=>16));
$myPicture->drawScale(array("MinDivHeight"=>50, "CycleBackground"=>TRUE,"DrawSubTicks"=>FALSE,"GridR"=>0,"GridG"=>0,"GridB"=>0,"GridAlpha"=>30,"Pos"=>SCALE_POS_TOPBOTTOM,"Mode"=>SCALE_MODE_MANUAL, "ManualScale"=>$AxisBoundaries, "ScaleSpacing"=>100)); //
Another, slightly dodgy way, is to create a dataset with whole numbers to before you call the drawScale function, then remove it, and add your actual data.
I did a couple of things to achieve this, first I set a fixed scale with a min and max.
$scaleConfig = array("Min"=>1,"Max"=>100); //set explicit scale size
And then when I use the drawScale() method I set the Factor property to 1:
$pImage->drawScale(array('Mode'=>SCALE_MODE_MANUAL,'Factors'=>array(1),'ManualScale'=>$scaleConfig,'DrawSubTicks' => false));
if you set "Factors" => array(10000) in drawScale function the pChart is showing intergers(1, 2). I found the solution myself.
精彩评论