TimeSeries Question

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
jaypee
Posts: 32
Joined: Fri Mar 24, 2006 2:35 am

TimeSeries Question

Post by jaypee » Tue Apr 18, 2006 2:01 am

i'm using DefaultCategoryDataset for my dataset.
my x axis contains dates... however i have double entries for my dates
i.e. in one date i may have 2 to 3 x axis values for the same date.

my data is

May 18, 2005 -0.084
May 25, 2005 -0.055
Jun 6, 2005 -0.084
Jun 11, 2005 -0.084
Jun 20, 2005 -0.184
Jun 28, 2005 -0.095
Jul 5, 2005 -0.155
Jul 11, 2005 -0.055
Jul 20, 2005 -0.084
Aug 26, 2005-0.084
Sep 2, 2005 -0.100
Sep 11, 2005 -0.089
Sep 18, 2005 -0.055
Sep 22, 2005 -0.055
Nov 5, 2005 -0.084
Nov 5, 2005 -0.071
Nov 12, 2005 -0.063
Nov 12, 2005 -0.063
Nov 13, 2005 -0.045
Nov 13, 2005 -0.055
Nov 13, 2005 -0.071
Jan 19, 2006 -0.100
Jan 19, 2006 -0.055
Jan 26, 2006 -0.071
Feb 1, 2006 -0.055
Feb 8, 2006 -0.055
Feb 15, 2006-0.071
Feb 21, 2006-0.055
Mar 8, 2006 -0.055
Mar 20, 2006-0.071

there are 3 entries for november 13, but my graph only graphs the 0.71 nov 13, 2006 value.

my graph right now only plots 25 points but as you can see there are 30 points all in all... how can i plot all of it?

i tried using timeseries still the same result

:(


please advice

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

Post by angel » Tue Apr 18, 2006 9:18 am

If you are using the CategoryDataset or the Timeseries you need to have different x values because the next same x value overwrites the old.

Either you add different hour/minute/second to your dataset or you can use an xyDataset.

jaypee
Posts: 32
Joined: Fri Mar 24, 2006 2:35 am

TimeSeries

Post by jaypee » Tue Apr 18, 2006 9:42 am

Thanks :)
I'll try it out.

I have a question about the range marker.... is there a way i can specify how long the marker will be?

jaypee
Posts: 32
Joined: Fri Mar 24, 2006 2:35 am

XYDataset

Post by jaypee » Tue Apr 18, 2006 10:09 am

i tried using the XYDataset.
i modified the TimeSeriesDemo5 example a bit

here is the code

Code: Select all

public class TimeSeriesDemo5 extends ApplicationFrame {
    public TimeSeriesDemo5(final String title) {
        super(title);
        final XYDataset dataset = createDataset();
        final JFreeChart chart = createChart(dataset);
        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        chartPanel.setMouseZoomable(true, false);
        setContentPane(chartPanel);
    }
    private XYDataset createDataset() {
        final TimeSeries series = new TimeSeries("Random Data");
        try {
	        series.add(new Day(1, 1, 1990), 10.4);
	        series.add(new Day(1, 1, 1990), 1.4);
	        series.add(new Day(1, 2, 1990), 15.4);
	        series.add(new Day(1, 2, 1990), 11.4);
	        series.add(new Day(1, 4, 1990), 6.4);
	        series.add(new Day(1, 6, 1990), 9.4);
        }
        catch (SeriesException e) {
	        System.err.println("Error adding to series");
        }
        return new TimeSeriesCollection(series);
    }

    private JFreeChart createChart(final XYDataset dataset) {
        return ChartFactory.createTimeSeriesChart(
            "Test", 
            "Day", 
            "Value", 
            dataset,
            false, 
            false, 
            false
        );
    }

    public static void main(final String[] args) {

        final String title = "\u20A2\u20A2\u20A2\u20A3\u20A4\u20A5\u20A6\u20A7\u20A8\u20A9\u20AA";
        final TimeSeriesDemo5 demo = new TimeSeriesDemo5(title);
        demo.pack();
        RefineryUtilities.positionFrameRandomly(demo);
        demo.setVisible(true);

    }

}
but when i run it says "Error adding to series"

how do i add points of the same date? please help

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

Post by angel » Tue Apr 18, 2006 10:27 am

Maybe this can help

Code: Select all

XYSeries series1 = new XYSeries("Series1", false, true);
...
while (rs.next()) {
series1.add(new Day(rs.getDate("dat")).getMiddleMillisecond(), rs.getInt("val"));
}

jaypee
Posts: 32
Joined: Fri Mar 24, 2006 2:35 am

Post by jaypee » Wed Apr 19, 2006 2:30 am

Thanks for the reply :)

I'll try it out.

ravik
Posts: 3
Joined: Fri Apr 21, 2006 9:18 am

hi can u help me?

Post by ravik » Fri Apr 21, 2006 9:20 am

Hi,

Can u send me the code for plotting multiple values for the same date?

jaypee
Posts: 32
Joined: Fri Mar 24, 2006 2:35 am

timeseries problem

Post by jaypee » Thu Apr 27, 2006 4:56 am

Ravik and I seem to have the same prob.

Here's the graph I'd like to do:
http://www.imagedump.com/index.cgi?pic ... 0&warned=y


But I'm having problems making it...

A Sample code would be very much appreciated. Thanks in advance.

doudou
Posts: 27
Joined: Tue Mar 14, 2006 6:05 pm

Post by doudou » Thu Apr 27, 2006 8:51 am

you should have a look at financial charts demos.

jaypee
Posts: 32
Joined: Fri Mar 24, 2006 2:35 am

Post by jaypee » Thu Apr 27, 2006 11:40 pm

Hi

could you point me to some urls for the demos.

thanks :-)

Locked