integral values and float axis labels

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Rich Unger

integral values and float axis labels

Post by Rich Unger » Thu Sep 12, 2002 6:18 pm

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

josh

Re: integral values and float axis labels

Post by josh » Thu Sep 12, 2002 6:37 pm

yAxis.setTickUnit(new NumberTickUnit(12.5,new DecimalFormat("0.#"));

Rich Unger

Re: integral values and float axis labels

Post by Rich Unger » Thu Sep 12, 2002 9:44 pm

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?

David Gilbert

Re: integral values and float axis labels

Post by David Gilbert » Thu Sep 12, 2002 11:17 pm

You can do this:

CategoryPlot plot = myChart.getCategoryPlot();
NumberAxis axis = (NumberAxis)plot.getRangeAxis();
axis.setStandardTickUnits(TickUnits.createIntegerTickUnits());

Regards,

DG.

Rich Unger

Re: integral values and float axis labels

Post by Rich Unger » Fri Sep 13, 2002 12:07 am

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

David Gilbert

Re: integral values and float axis labels

Post by David Gilbert » Fri Sep 13, 2002 11:09 am

I've just changed the selectAutoTickUnit method in HorizontalNumberAxis from private to protected, to be consistent with VerticalNumberAxis.

Regards,

DG.

Locked