PChart - Show a fixed number of lablels in X-Axis

6.5k Views Asked by At

How to show only a fixed number of labels in X-Axis ??

I have tried "LabelSkip", but I think it works only with an interval and not with fixed number of labels.

Here is a print-screen of my chart: enter image description here

4

There are 4 best solutions below

0
On

I have used "LabelSkip"=>(count($series)/10) to have 10 labels on the X axis

Works fine for me

0
On

Joel Deutscher's answer worked for me. I would have up voted it, but I do not have enough stackoverflow reputation for that.

It works exactly as he said: Chart Width / MinDivHeight = Number of labels on the chart.

Here's my code

$scaleSettings = array("DrawXLines"=>FALSE,"Mode"=>SCALE_MODE_START0,"GridR"=>0,"GridG"=>0,"GridB"=>0,"GridAlpha"=>10,"Pos"=>SCALE_POS_TOPBOTTOM, "MinDivHeight" => 50);

$pchart->chart->drawScale($scaleSettings);
3
On

Are you using pChart 1 or pChart2 ?

This can be achived in pChart 1 using setFixedScale

To draw a scale with a maximum value of 10 with 5 points use the following command before drawing the scale

$Graph->setFixedScale(0,10,5);
0
On

I know it has been a while since this was asked, but it may help someone:

$maxXLabels = 5; // How many labels on-screen?

$labelSkip = floor( count( $timestamp ) / $maxXLabels ); // how many should we skip?
$myPicture->drawScale(array("LabelSkip"=>$labelSkip));