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
Date problem with TimeSeries
RE: Date problem with TimeSeries
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.
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.
RE: Date problem with TimeSeries
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
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
RE: Date problem with TimeSeries
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
...
// 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
RE: Date problem with TimeSeries
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
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
RE: Date problem with TimeSeries
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.
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.
Not Found Method
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
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