Date problem with TimeSeries

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

Date problem with TimeSeries

Post by Jacqueline » Wed Dec 19, 2001 8:23 pm

Hi,


I´m having problems with getting a date to the TimeSeries Chart.
I´m using a database query that returns a DateTime value and since the Java only supports date, Time and TimeStamp it is not working with DateTime. The x axis don´t display the correct dates.

Any sugestions?

Thanks in Advance,

Jacqueline

David Gilbert

RE: Date problem with TimeSeries

Post by David Gilbert » Thu Dec 20, 2001 9:18 am

Hi Jacqueline,

I'm not familiar with the DateTime class.

All the time series plots in JFreeChart are produced using data from an XYDataset (or some extension like HighLowDataset), and if you study that interface you will notice that it works with Number objects. The HorizontalDateAxis class simply assumes that the Number it is given for the x-value represents the number of milliseconds since 1-Jan-1970. This is consistent with java.util.Date, so the axis uses java.util.Date to work out tick labels etc. But the underlying data is still numerical.

So you need to find a way to convert your DateTime class to milliseconds since 1-Jan-1970.

Regards,

DG.

Jacqueline

RE: Date problem with TimeSeries

Post by Jacqueline » Thu Dec 20, 2001 12:38 pm

Hi David,


Thanks a lot for your reply. Problem solved.
Can we change the format of the date that appears on the chart, I mean, it appears something like 12-Jan-2001. How can I convert it in order to appear in the chart 12-01-2001. Can you specify the what file(s) do I need to change and what?
Thanks in Advance,

Jacqueline

Akmal

RE: Date problem with TimeSeries

Post by Akmal » Thu Dec 20, 2001 3:39 pm

you can do that with the following code:
...
// private DateAxis myAxis;
SimpleDateFormat hAxisFormat = myAxis.getTickLabelFormatter ();
hAxisFormat.applyPattern ("d-MM-yyyy");
// I think this should work fine... for any further formats
// have a look at SimpleDateFormat class

cheers ;)

Akmal

Jacqueline

RE: Date problem with TimeSeries

Post by Jacqueline » Thu Dec 20, 2001 5:04 pm

thanks Akmal,

Works fine.

I´m new at JfreeCharts, need help on this: I have a query that retrieves a date and a number but need to display it on a VerticalBarChart and LineChart. Is it possible or these charts don´t accept dates?


Regards,

Jacqueline

David Gilbert

RE: Date problem with TimeSeries

Post by David Gilbert » Thu Dec 20, 2001 6:31 pm

Hi Jacqueline,

The vertical bar charts and the line charts are based on the CategoryDataset, so you can't use dates for them.

If you want to create a bar chart from time series data (there is one in the demo application) then you need to have an IntervalXYDataset (the TimeSeriesCollection class implements this interface) which you can pass to the ChartFactory.createVerticalXYBarChart method.

Hope this helps,

DG.

jacqueline

Not Found Method

Post by jacqueline » Thu Dec 20, 2001 7:49 pm

Hi David,

I haven´t found that method you´ve referenced me, perhaps because I have the 0.5.6 version of JFreeChart.
Can you confirm this? Or is it a workaround?

Thanks in Advance,

Jacqueline

David Gilbert

RE: Not Found Method

Post by David Gilbert » Thu Dec 20, 2001 11:13 pm

The chart type and factory method were new in 0.6.0.

DG.

Locked