SerialDate MINIMUM_YEAR_SUPPORTED question
-
- Posts: 2
- Joined: Wed Nov 24, 2004 5:27 pm
- Location: National Climatic Data Center (Asheville, NC, USA)
- Contact:
SerialDate MINIMUM_YEAR_SUPPORTED question
Hello,
I need to plot a time series with dates from 1800 to present. I noticed that the SerialDate class has a lower bound of 1900 (MINIMUM _YEAR_SUPPORTED). Is it possible to me to change this to 1800 in the SerialDate class? Is there another graphing option I could use?
Thanks,
Steve
I need to plot a time series with dates from 1800 to present. I noticed that the SerialDate class has a lower bound of 1900 (MINIMUM _YEAR_SUPPORTED). Is it possible to me to change this to 1800 in the SerialDate class? Is there another graphing option I could use?
Thanks,
Steve
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
The SerialDate class is some code I wrote a few years ago to (roughly) match the way that spreadsheets represent dates. That's where the lower limit of 1900 came from.
Later, I based internals of the Day class (a subclass of RegularTimePeriod) on the SerialDate class, because I knew it would work reasonably well...but I never thought about the lower limit on the year. In fact, I'm surprised that you are the first to report it.
I don't think it will be a big problem to fix, but it will take a little time to ensure that nothing gets broken. In the meantime, a workaround would be to create a TimeSeries using the FixedMillisecond class as the time period - FixedMillisecond is just a thin wrapper around Java's Date class. You shouldn't run into any year problems that way.
Later, I based internals of the Day class (a subclass of RegularTimePeriod) on the SerialDate class, because I knew it would work reasonably well...but I never thought about the lower limit on the year. In fact, I'm surprised that you are the first to report it.
I don't think it will be a big problem to fix, but it will take a little time to ensure that nothing gets broken. In the meantime, a workaround would be to create a TimeSeries using the FixedMillisecond class as the time period - FixedMillisecond is just a thin wrapper around Java's Date class. You shouldn't run into any year problems that way.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- Posts: 2
- Joined: Wed Nov 24, 2004 5:27 pm
- Location: National Climatic Data Center (Asheville, NC, USA)
- Contact:
Hi Dave,
Thanks for your response. I changed the TimeSeries to use a FixedMillisecond class but I am again getting an error. It appears that the Day and Year classes are still used to create the Axis labels. Here is my exception and stack trace:
EXCEPTION: java.lang.IllegalArgumentException: The 'year' argument must be in range 1900 to 9999.
STACK TRACE:
org.jfree.date.SpreadsheetDate.(Unknown Source)
org.jfree.date.SerialDate.createInstance(Unknown Source)
org.jfree.data.time.Day.(Day.java:107)
org.jfree.data.time.Year.getFirstMillisecond(Year.java:187)
org.jfree.data.time.RegularTimePeriod.getFirstMillisecond(RegularTimePeriod.java:137)
org.jfree.data.time.RegularTimePeriod.getFirstMillisecond(RegularTimePeriod.java:125)
org.jfree.chart.axis.DateAxis.calculateDateForPosition(DateAxis.java:895)
org.jfree.chart.axis.DateAxis.refreshTicksHorizontal(DateAxis.java:1402)
org.jfree.chart.axis.DateAxis.refreshTicks(DateAxis.java:1305)
org.jfree.chart.axis.ValueAxis.drawTickMarksAndLabels(ValueAxis.java:588)
org.jfree.chart.axis.DateAxis.draw(DateAxis.java:1522)
org.jfree.chart.plot.XYPlot.drawAxes(XYPlot.java:2113)
org.jfree.chart.plot.XYPlot.draw(XYPlot.java:1744)
org.jfree.chart.JFreeChart.draw(JFreeChart.java:905)
org.jfree.chart.JFreeChart.createBufferedImage(JFreeChart.java:1038)
org.jfree.chart.ChartUtilities.writeChartAsPNG(ChartUtilities.java:196)
org.jfree.chart.ChartUtilities.writeChartAsPNG(ChartUtilities.java:116)
Thanks for all of your help.
Steve
Thanks for your response. I changed the TimeSeries to use a FixedMillisecond class but I am again getting an error. It appears that the Day and Year classes are still used to create the Axis labels. Here is my exception and stack trace:
EXCEPTION: java.lang.IllegalArgumentException: The 'year' argument must be in range 1900 to 9999.
STACK TRACE:
org.jfree.date.SpreadsheetDate.(Unknown Source)
org.jfree.date.SerialDate.createInstance(Unknown Source)
org.jfree.data.time.Day.(Day.java:107)
org.jfree.data.time.Year.getFirstMillisecond(Year.java:187)
org.jfree.data.time.RegularTimePeriod.getFirstMillisecond(RegularTimePeriod.java:137)
org.jfree.data.time.RegularTimePeriod.getFirstMillisecond(RegularTimePeriod.java:125)
org.jfree.chart.axis.DateAxis.calculateDateForPosition(DateAxis.java:895)
org.jfree.chart.axis.DateAxis.refreshTicksHorizontal(DateAxis.java:1402)
org.jfree.chart.axis.DateAxis.refreshTicks(DateAxis.java:1305)
org.jfree.chart.axis.ValueAxis.drawTickMarksAndLabels(ValueAxis.java:588)
org.jfree.chart.axis.DateAxis.draw(DateAxis.java:1522)
org.jfree.chart.plot.XYPlot.drawAxes(XYPlot.java:2113)
org.jfree.chart.plot.XYPlot.draw(XYPlot.java:1744)
org.jfree.chart.JFreeChart.draw(JFreeChart.java:905)
org.jfree.chart.JFreeChart.createBufferedImage(JFreeChart.java:1038)
org.jfree.chart.ChartUtilities.writeChartAsPNG(ChartUtilities.java:196)
org.jfree.chart.ChartUtilities.writeChartAsPNG(ChartUtilities.java:116)
Thanks for all of your help.
Steve
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
I will try to look at this on Monday, it seems like an important thing to get fixed...
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


java.lang.IllegalArgumentException: The 'year' argument ...
How was it?david.gilbert wrote:I will try to look at this on Monday, it seems like an important thing to get fixed...
I'm facing the same problem too!
If I adjust the input parameter before putting in as argument, will it be resolved?
Is this a Locale problem?
by Avatar Ng
Avatar Ng
Fixed
Had it resolved (for my case only)david.gilbert wrote:I will try to look at this on Monday, it seems like an important thing to get fixed...
instead of :
Code: Select all
int day = date.getDay()+1;
int month = date.getMonth()+1;
int year = date.getYear();
((TimeSeries)pop.get(item)).add(new Day(day, month, year), success_rate);
Code: Select all
int day = date.getDay()+1;
int month = date.getMonth()+1;
int year = 1900+date.getYear();
(TimeSeries)pop.get(item)).add(new Day(day, month, year), success_rate)
However having the year limit setting from 1900 to 9999 is unreasonable & unportable, please remove the validity check (validity check should be developer's responsible/ and that makes Jfree chart more portable).
by Avatar Ng (blog: avatar21.superihost.com)
Avatar Ng
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
The lower bound for the year (currently 1900) needs to be removed, definitely. I had hoped to get it done for 1.0.3, but it isn't going to make it into that release. Hopefully 1.0.4...
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- Posts: 1
- Joined: Tue May 12, 2009 7:35 pm
Re: SerialDate MINIMUM_YEAR_SUPPORTED question
I'm trying to graph a time series with data from the 1800's. Is the minimum date going to be removed any time soon?
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: SerialDate MINIMUM_YEAR_SUPPORTED question
Can you give me an example that doesn't work? It is a while since I looked at this, but I do remember fixing the time series charts to support years before 1900. For example, try running the following:
Code: Select all
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.data.time.RegularTimePeriod;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.time.Year;
import org.jfree.data.xy.XYDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
/**
* A times series chart with years from 1700
*/
public class DemoYYYY extends ApplicationFrame {
/**
* A demonstration application showing...
*
* @param title the frame title.
*/
public DemoYYYY(String title) {
super(title);
ChartPanel chartPanel = (ChartPanel) createDemoPanel();
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
setContentPane(chartPanel);
}
/**
* Creates a chart.
*
* @param dataset a dataset.
*
* @return A chart.
*/
private static JFreeChart createChart(XYDataset dataset) {
JFreeChart chart = ChartFactory.createTimeSeriesChart(
"Random Values from History", // title
"Year", // x-axis label
"Value", // y-axis label
dataset, // data
true, // create legend?
true, // generate tooltips?
false // generate URLs?
);
return chart;
}
/**
* Creates a dataset, consisting of two series of monthly data.
*
* @return The dataset.
*/
private static XYDataset createDataset() {
TimeSeries s1 = new TimeSeries("Random Data");
RegularTimePeriod t = new Year(1700);
double v = 100.0;
s1.add(t, v);
for (int i = 0; i < 310; i++) {
t = t.next();
v = v * (1 + (Math.random() - 0.49) / 100);
s1.add(t, v);
}
TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(s1);
return dataset;
}
/**
* Creates a panel for the demo (used by SuperDemo.java).
*
* @return A panel.
*/
public static JPanel createDemoPanel() {
JFreeChart chart = createChart(createDataset());
ChartPanel panel = new ChartPanel(chart);
panel.setFillZoomRectangle(true);
panel.setMouseWheelEnabled(true);
return panel;
}
/**
* Starting point for the demonstration application.
*
* @param args ignored.
*/
public static void main(String[] args) {
DemoYYYY demo = new DemoYYYY("DemoYYYY");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
}
}
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Re: SerialDate MINIMUM_YEAR_SUPPORTED question
Hi !
Looks like Year is working, but Day isn't... just tried, because I had to show daily data starting from 18xx. Year isn't using SerialDate and has it's own limits allowing for pre 1900 values.
If you give a hint on how to fix this, I'd give it a try...
Thanks for a great tool,
Tom
Looks like Year is working, but Day isn't... just tried, because I had to show daily data starting from 18xx. Year isn't using SerialDate and has it's own limits allowing for pre 1900 values.
If you give a hint on how to fix this, I'd give it a try...
Thanks for a great tool,
Tom