|
Controlling the Y axis step rate |
Posted by DC Kelley on Apr-09-2011 02:10 |
|
Is these a way to force the Y axis to use a defined modulo step value in the labels (say every 0.25 steps)?
I see how to control the displayed digits and performs simple math operations using the setLabelFormat() line with lines like:
c->yAxis()->setLabelFormat("{={value}/1000|0,}"); // in km
c->yAxis()->setLabelFormat("{value|2}"); // SNR, 2 digits
but I do not see a way to force the values chosen to align this way. And I would prefer not to calculate a set of labels if that can be avoided (the individual layers are not well grouped to support doing this).
The below chart shows this, the default spacing of 0.1 is not as pretty as a spacing of 0.25 would be.
|
Re: Controlling the Y axis step rate |
Posted by Peter Kwan on Apr-10-2011 18:21 |
|
Hi DC Kelley,
If you know the label spacing is 0.25 units, your code should be able to configure the axis scale easily, like:
c->yAxis()->setLinearScale(minValue, maxValue, 0.25);
or
c->yAxis()->setLinearScale(floor(minValue/0.25)*0.25, ceil(maxValue/0.25)*0.25, 0.25);
However, for arbitrary data, the key issue is that it is hard to determine the tick spacing. What is good for a certain data range may look bad for another data range. ChartDirector auto-scaling will try to determine a tick increment that is reasonable for the data range.
If your actual intention is to have the labels spaced more widely, you may use Axis.setTickDensity. By default, the tick density is 20 pixels, which means the label spacing must be at least 20 pixels. If you want a wide spacing, you may use a bigger spacing, like 50 pixels. ChartDirector auto-scaling will then come up with another scale and label spacing that meets the requirement.
c->yAxis()->setTickDensity(50);
Hope this can help.
Regards
Peter Kwan |
Re: Controlling the Y axis step rate |
Posted by DC Kelley on Apr-11-2011 02:09 |
|
As you observe, it can be a bit hard to determine the range of min-max until the axis layout has occurred, and I do not care to have the delay to do that twice. I guess I will need to rework my layer creation logic a bit to gather the running min-max values of relevant data as they are built up and then can then proceed as you suggested to define the axis. In this case, I will always know the LSB units involved due to the basic chart type, just not the data ranges until the layers are all processed, not a bit deal, just another inline step for each layer. Many thanks. DCK |
|