|
Legend Labels |
Posted by Maxx Power on Aug-15-2013 10:46 |
|
Hey,
I have a Contour Layer with a linear color axis of about 20 steps. Everything looks great
except the legend is showing too many labels for my liking.
So I was wondering if there is a way to only show every second label in the legend..??
If I use setLabels or setLabelStep it will actually change the number of classes which I don't
want to do, I just want to skip every second label...
Cheers
Maxx... |
Re: Legend Labels |
Posted by Peter Kwan on Aug-16-2013 00:44 |
|
Hi Maxx,
If you can set the color axis scale, you can use minor ticks to skip the label. For
example:
#color axis from 0 to 100, with a label every 10 units, and a minor tick every 5 units
$cAxis->setLinearScale(0, 100, 10, 5);
If the color axis is auto-scaled by ChartDirector, the following code can remove every
other label:
.... create the chart as usual ....
#layout the axis labels
$c->layout();
#replace half of the labels with minor tick
$ticks = $cAxis->getTicks();
for ($i = 1; $i < count($ticks); $i += 2)
$cAxis->addLabel($ticks[i], "-");
Note that if the color axis is auto-scaled by ChartDirector, the labels depend on the
actual data. There is no guarantee that they will be an even number or odd number of
labels. For example, the labels can be [0, 1, 2, 3, 4, 5, 6, 7]. If you remove half of the
labels, they will become [0, "", 2, "", 4, "", 6, ""]. Note that the axis end point at 7 does
not have any label. So if the axis is auto-scaled (so that the number of labels are not
predictable), and you remove some labels, there is no guarantee that the axis end point
will still have a label position.
Hope this can help.
Regards
Peter Kwan |
Re: Legend Labels |
Posted by Peter Kwan on Aug-16-2013 00:44 |
|
Hi Maxx,
In my last message, the line:
$cAxis->addLabel($ticks[i], "-");
should be:
$cAxis->addLabel($ticks[$i], "-");
Regards
Peter Kwan |
Re: Legend Labels |
Posted by Maxx Power on Aug-16-2013 07:48 |
|
Ahh, perfect..!
The minor ticks did the trick..
No need to layout the chart first, or go through the ticks, just:
From: $cAxis->setLinearScale(0, 100, 10); # Prints a label at every class
To: $cAxis->setLinearScale(0, 100, 20, 10); # Prints a label every second class
Both have 10 classes.
Thanks Peter... |
|