why setAutoTickValue(false)didn't do as I expected

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

why setAutoTickValue(false)didn't do as I expected

Post by cambridge zhang » Fri Sep 14, 2001 7:15 am

Thanks a lot for the excellent software -JFreeChart.I'm using JFreeChart to implement the widespread free network management software---MRTG (Multi Routers Traffic Graphics). It does much helps to me!

hen I used HorzontalDateAxis,I need to adjust the tick label unit,however, I find sth surprising:

1. case one :
XYDataSource xyData = createXYDataSource(data);
JFreeChart chart = JFreeChart.createTimeSeriesChart(xyData);

/**set the horizontal axis label unit */
Plot myPlot = chart.getPlot();
DateAxis myHorizontalAxis = (DateAxis) myPlot.getAxis(Plot.HORIZONTAL_AXIS);
myHorizontalAxis.getTickLabelFormatter().applyPattern("H");
myHorizontalAxis.setTickUnit(new DateUnit(Calendar.HOUR_OF_DAY, 1));
myHorizontalAxis.setAutoTickValue(false);

/**set VerticalAxis tick labels */
VerticalNumberAxis vnAxis = (VerticalNumberAxis)chart.getPlot().getAxis(Plot.VERTICAL_AXIS);
vnAxis.setAutoRangeIncludesZero(false);

/**Save as Jpeg file */
BufferedImage chartImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = (Graphics2D)chartImage.getGraphics();
BufferedImage chartImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = (Graphics2D)chartImage.getGraphics();
chart.draw(g2, new Rectangle2D.Double(0, 0, width, height));
.......


Result: it throws a lot of errors when running, NullPointerException
setTime(Unknow Source)
calcuteLowVisibalTick(Unknown source)
.........

2.when I comment
//myHorizontalAxis.setTickUnit(new DateUnit(Calendar.HOUR_OF_DAY, 1));
// myHorizontalAxis.setAutoTickValue(false);

Result: it runs well,but it didn't show the pattern I had expected to
it showed dd-MMM hh:ss

3.At last I have to add this to the code in the case 1,
Axis myHorizontalDateAxis = new HorizontalDateAxis(
myHorizontalAxis.getLabel(),
myHorizontalAxis.getLabelFont(),
myHorizontalAxis.getLabelPaint(),
myHorizontalAxis.getLabelInsets(),
true,
myHorizontalAxis.getTickLabelFont(),
myHorizontalAxis.getTickLabelPaint(),
myHorizontalAxis.getTickLabelInsets(),
false,
true,
myHorizontalAxis.getTickMarkStroke(),
true,
myHorizontalAxis.getMinimumDate(),
myHorizontalAxis.getMaximumDate(),
myHorizontalAxis.getAutoTickValue(),
myHorizontalAxis.getTickUnit(),
myHorizontalAxis.getTickLabelFormatter(),
true,
myHorizontalAxis.getGridStroke(),
myHorizontalAxis.getGridPaint());

myPlot.setHorizontalAxis(myHorizontalDateAxis);

Result: It does as I expected.

Question:
I just can't understand why I should create a new HorzintalDateAxis in order to use the setTickUnit(false),
since when JFreeChart.createTimeSeriesChart(xyData),it already new a
HorzintalDateAxis .

Please be kind enough to tell me why!
Thanks
Sincerely

David Gilbert

RE: why setAutoTickValue(false)didn't do as I expe

Post by David Gilbert » Mon Sep 17, 2001 2:42 pm

Hi,

Thanks for your post. There's definitely some funny quirks in the date axis code! In about three weeks time I will have an opportunity to do some serious work on JFreeChart (which unfortunately hasn't been possible for most of the last year) so I will take a good look at the problem then. In the meantime I hope having the source code is helping you...

Regards,

DG.

Locked