Date Format

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

Date Format

Post by Julio Guzman » Sat Apr 28, 2001 2:52 am

I am currently graphing on the Time Series Chart by hours on the x-axis. So it starts from 0:00 and goes to 0:00 (or 24:00). When I graph my data it graphs the x-axis as Jan 1 - 0:00. I know that it's doing this because it is setting the default month and day, but is there anyway to clear out the Month and date and only have the time. In other words, what is the date format that I would have to send the DefaultXYDataSource constructor to hide the month and date. I want it where I can do both (month, date, year) and time. Thanks in advance for the help.

Regards,
Julio G.

Julio Guzman

RE: Date Format

Post by Julio Guzman » Thu May 17, 2001 6:40 pm

I'm still stuck on this one, can someone give me some hints....

thanks in advance,
julio

Daniel Serodio

RE: Date Format

Post by Daniel Serodio » Wed May 23, 2001 2:46 am

I don't think you can pass some parameter to DefaultXYDataSource to accomplish this. The way I'm doing it is:

// Create your chart
JFreeChart chart = JFreeChart.createTimeSeriesChart(dataSource);

// Now set the axis' format
Plot plot = chart.getPlot();
DateAxis hAxis = (DateAxis)plot.getAxis(Plot.HORIZONTAL_AXIS);
SimpleDateFormat hAxisFormat = hAxis.getTickLabelFormatter();
fAxisFormat.applyPattern("H:m");

Hope this solves you problem.

[]'s
Daniel Serodio

Julio Guzman

RE: Date Format

Post by Julio Guzman » Wed May 23, 2001 1:33 pm

Well,

Thanks for the help, but it just didn't do the job. For some reason I guess it simply ignores it and keeps on displaying the time along with the month and day. The month and day are always "Jan 1" as if it knew those values were 0 but it still displayed them. If you have any other ideas I would greatly appreciate them.

thanx for the help,
julio

Daniel Serodio

RE: Date Format

Post by Daniel Serodio » Wed May 23, 2001 6:53 pm

I see. I guess it's related to this bug: http://www.jrefinery.com/forums/read.ph ... =386&t=386

As far as I know, it's only a problem if you're using automatic tick values. If your tick values have a constant unit, eg, hourly ticks, you can use:

// Now set the axis' format
Plot plot = chart.getPlot();
DateAxis hAxis = (DateAxis)plot.getAxis(Plot.HORIZONTAL_AXIS);
hAxis.setAutoTickValue(false);
hAxis.setTickUnit(new DateUnit(Calendar.HOUR, 1)
SimpleDateFormat hAxisFormat = hAxis.getTickLabelFormatter();
fAxisFormat.applyPattern("H:m");

Please lemme know it this works.

[]'s
Daniel Serodio

Julio Guzman

RE: Date Format

Post by Julio Guzman » Tue May 29, 2001 8:11 pm

Daniel,

Thanks a million, that did the trick...i could not make it work until I looked at the actual Date Axis class and found out that Calendar.HOUR was not available, but HOUR_OF_DAY was. It works beautifully now....

thanks again,
Julio

Locked