date on horizontal axis

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

date on horizontal axis

Post by Andrea Ponte » Wed Apr 17, 2002 11:47 am

Hello,
I try to configure my vertical axis with date label on the ticks instead of number but i had no success.
This is my code I get it from a post of David but it seems dont work

XYPlot xyPlot = chart.getXYPlot();
// Configure vertical axis
NumberAxis rangeAxis = (NumberAxis)xyPlot.getRangeAxis();
rangeAxis.setMaximumAxisValue(gD.max+5);
// Set ticks vertical
HorizontalNumberAxis numberAxis= (HorizontalNumberAxis)xyPlot.getDomainAxis();
numberAxis.setVerticalTickLabels(true);

// Try to insert dates but the first line down give me a class
//cast exception at run time

HorizontalDateAxis dateAxis = (HorizontalDateAxis) xyPlot.getHorizontalAxis ();
dateAxis.setAutoTickUnitSelection(false);
dateAxis.setTickUnit(new DateUnit(Calendar.MONTH,1));
SimpleDateFormat sdf = dateAxis.getTickLabelFormatter();
sdf.applyPattern("dd-MM-yy");

Can someone help?
Best Regards Andrea

Locked