|
How to get max value of axis after setLinearScale |
Posted by Niels Egberts on Nov-24-2011 18:13 |
|
I have a chart where I set the max value of linear scale to for instance 378000 and the minimum value of 0.
The chart is drawn with numbers 0, 100000, 200000, 300000 and at the end 400000.
How can I retrieve this 400000? axis.getMaxValue returns 100...
Thanks for any help!
Here's the code:
Axis yAxis = chart.yAxis();
yAxis.setColors(Chart.Transparent, color3);
yAxis.setLinearScale(0, 378000);
yAxis.setLabelStyle("Arial", 9, color3); |
Re: How to get max value of axis after setLinearScale |
Posted by Peter Kwan on Nov-24-2011 22:44 |
|
Hi Niels,
If your code only provides the min and max scale (0 to 378000) without providing the tick increment, ChartDirector will automatically determine the tick increment (in your case, it is 100000), and it may extend the scale so that it has an integral number of increments. That's why the scale becomes 0 to 400000.
If you do not want ChartDirector to extend the scale, you may use:
yAxis.setRounding(false, false);
With the above code, the axis scale will be 0 to 378000 exactly.
If you would like ChartDirector to extend the scale to an integral number of increments, and would like to know what is the final scale, you would need to "layout" the axis first, which can be done by "making the chart" (eg. calling makeChart, makeWebImage, etc), or calling "layout" or "layoutAxes".
For example:
chart.layoutAxes();
double maxValue = yAxis.getMaxValue();
Note that during layout, ChartDirector will determine the scale of all the axes at the same time (as there can be multiple x-axes and y-axes on the chart, and they can be dependent on each others). The axis scale may depend on your data (in many cases, ChartDirector sets the axis range based on the data), so your code should pass all the data to ChartDirector first, before calling XYChart.layoutAxes.
Hope this can help.
Regards
Peter Kwan |
|