This works when I want 2 or 4 divisions, but if I set it to 3, I still get 2 divisions. And if I set nNumDivisions to any number between 5 and 9, I only get 4. But if I set it to 10, I get 8 divisions.
The Y axis is behaving perfectly.
Am I missing a call or a setting?
The attached graph shows what I mean. It has 3 vertical divisions and 2 horizontal (even though I've instructed it to display 3 horizontal divisions).
The setTickDensity sets the minimum pixel distance between two ticks when the axis is auto-scaled by ChartDirector. The actual distance can be bigger than the minimum distance.
For example, if the axis scale is 0 to 40, and you set the tick density so that there can be 4 labels on the chart, the labels will be 0, 13.3333333, 26.6666666, 40. If the axis is auto-scaled by ChartDirector, ChartDirector will prefer (0, 10, 20, 30, 40) or (0, 20, 40). The (0, 10, 20, 30, 40) cannot be used because the tick density allow at most 4 labels, so (0, 20, 40) is used.
ChartDirector auto-scaling will ensure the actual labels look "nice" and match the data. The 0, 20, 40 is acceptable while 0, 13.3333333, .... does not look "nice". That is why the actual tick distance can be bigger, as it needs some degree of freedom to satisfy all these requirements.
The only method to ensure there is always 4 labels is to specify the scale with your own code, using Axis.setLinearScale. For example, you can use: