SerialDate MINIMUM_YEAR_SUPPORTED question

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
steve.ansari
Posts: 2
Joined: Wed Nov 24, 2004 5:27 pm
Location: National Climatic Data Center (Asheville, NC, USA)
Contact:

SerialDate MINIMUM_YEAR_SUPPORTED question

Post by steve.ansari » Wed Nov 24, 2004 5:41 pm

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

angel
Posts: 899
Joined: Thu Jan 15, 2004 12:07 am
Location: Germany - Palatinate

Post by angel » Thu Nov 25, 2004 8:18 am

y1.9k bug :wink:

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Thu Nov 25, 2004 9:34 am

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.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

steve.ansari
Posts: 2
Joined: Wed Nov 24, 2004 5:27 pm
Location: National Climatic Data Center (Asheville, NC, USA)
Contact:

Post by steve.ansari » Tue Nov 30, 2004 7:14 pm

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

dchheda

Post by dchheda » Wed Jul 06, 2005 8:42 pm

I too have the same problem. Did you find any solution for this?

Thank you.
dchheda

Guest

Post by Guest » Wed Jul 13, 2005 8:26 pm

Hello,

I did not figure out a fix to the TimeSeries problem.

Mr. Gilbert - is this something that has been fixed in a newer release?

Thanks,
Steve

Jii
Posts: 128
Joined: Thu Apr 21, 2005 11:17 am

Post by Jii » Thu Dec 15, 2005 9:52 am

I'm having this problem...

seimen
Posts: 3
Joined: Mon Jul 24, 2006 12:29 pm

Post by seimen » Thu Aug 10, 2006 10:51 am

i too have this problem. does anybody know how it can be fixed?

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Fri Aug 11, 2006 6:41 am

I will try to look at this on Monday, it seems like an important thing to get fixed...
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

ngavarta
Posts: 2
Joined: Fri Nov 10, 2006 2:00 am
Location: KL, Malaysia
Contact:

java.lang.IllegalArgumentException: The 'year' argument ...

Post by ngavarta » Fri Nov 10, 2006 2:04 am

david.gilbert wrote:I will try to look at this on Monday, it seems like an important thing to get fixed...
How was it?
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

ngavarta
Posts: 2
Joined: Fri Nov 10, 2006 2:00 am
Location: KL, Malaysia
Contact:

Fixed

Post by ngavarta » Fri Nov 10, 2006 4:55 am

david.gilbert wrote:I will try to look at this on Monday, it seems like an important thing to get fixed...
Had it resolved (for my case only)

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);
changed to:

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)
Hope this will be helpful to some of you.

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

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Fri Nov 10, 2006 10:27 am

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

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

russTbaker
Posts: 1
Joined: Tue May 12, 2009 7:35 pm

Re: SerialDate MINIMUM_YEAR_SUPPORTED question

Post by russTbaker » Tue May 12, 2009 7:37 pm

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?

david.gilbert
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

Post by david.gilbert » Tue May 12, 2009 9:08 pm

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

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

schnirkel
Posts: 2
Joined: Mon Jun 15, 2009 10:18 pm

Re: SerialDate MINIMUM_YEAR_SUPPORTED question

Post by schnirkel » Mon Jun 15, 2009 10:27 pm

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

Locked