If I'm graphing integral values, is there any way to enforce integral labels on the value axis?
I'm charting "number of page hits". The max value is 50. So, I've got a y-axis with 0, 12.5, 25, 37.5, and 50...
Thanks,
Rich
integral values and float axis labels
Re: integral values and float axis labels
yAxis.setTickUnit(new NumberTickUnit(12.5,new DecimalFormat("0.#"));
Re: integral values and float axis labels
Thanks for the pointer. Unfortunately, I don't know how big the values of my data set are going to be beforehand. What I'd like to do is something like:
CategoryPlot plot = (CategoryPlot)((JFreeChart)chart).getPlot();
NumberAxis axis = (NumberAxis)plot.getRangeAxis();
NumberTickUnit oldTickUnit = axis.getTickUnit();
NumberTickUnit newTickUnit = new NumberTickUnit(
Math.round( oldTickUnit.getSize() ),
new DecimalFormat("0.#") );
axis.setTickUnit(newTickUnit);
However, until draw() is called, the oldTickUnit will have the default size of 1.0.
I guess this amounts to a feature request that NumberAxis.refreshTicks() optionally restrain itself to integral values.
David?
CategoryPlot plot = (CategoryPlot)((JFreeChart)chart).getPlot();
NumberAxis axis = (NumberAxis)plot.getRangeAxis();
NumberTickUnit oldTickUnit = axis.getTickUnit();
NumberTickUnit newTickUnit = new NumberTickUnit(
Math.round( oldTickUnit.getSize() ),
new DecimalFormat("0.#") );
axis.setTickUnit(newTickUnit);
However, until draw() is called, the oldTickUnit will have the default size of 1.0.
I guess this amounts to a feature request that NumberAxis.refreshTicks() optionally restrain itself to integral values.
David?
Re: integral values and float axis labels
You can do this:
CategoryPlot plot = myChart.getCategoryPlot();
NumberAxis axis = (NumberAxis)plot.getRangeAxis();
axis.setStandardTickUnits(TickUnits.createIntegerTickUnits());
Regards,
DG.
CategoryPlot plot = myChart.getCategoryPlot();
NumberAxis axis = (NumberAxis)plot.getRangeAxis();
axis.setStandardTickUnits(TickUnits.createIntegerTickUnits());
Regards,
DG.
Re: integral values and float axis labels
Wow, I feel sheepish now. I totally missed that one!
I'd just finished this whole workaround subclassing the axis class and wrapping the selectAutoTickUnit() method (which only worked on vertical axes because selectAutoTickUnit is private in the horizontal axis, protected in the vertical).
Talk about going down the wrong path!
Rich
I'd just finished this whole workaround subclassing the axis class and wrapping the selectAutoTickUnit() method (which only worked on vertical axes because selectAutoTickUnit is private in the horizontal axis, protected in the vertical).
Talk about going down the wrong path!
Rich
Re: integral values and float axis labels
I've just changed the selectAutoTickUnit method in HorizontalNumberAxis from private to protected, to be consistent with VerticalNumberAxis.
Regards,
DG.
Regards,
DG.