Need a sample on MovingAverage

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

Need a sample on MovingAverage

Post by Amit » Tue Feb 25, 2003 8:08 pm

Can anyone post a working sample of MovingAverage.
I am doing :
===================

XYDataset avgds = new MovingAverage().createMovingAverage(ds, "Average", 34, 0);

JFreeChart chart = ChartFactory.createTimeSeriesChart
("AX Success Rate", // Title
"Date", // X-Axis label
"Percentage", // Y-Axis label
avgds, // Dataset
true, // Show legend
true,
true
);

=====================
and I get the following error in the 1st line.
ds is a JDBCXYDataset
=====================
java.lang.ArrayIndexOutOfBoundsException: 2147483647 >= 34
at java.util.Vector.elementAt(Unknown Source)
at com.jrefinery.data.JDBCXYDataset.getXValue(Unknown Source)
at com.jrefinery.data.MovingAverage.createMovingAverage(Unknown Source)
at com.jrefinery.data.MovingAverage.createMovingAverage(Unknown Source)
at testclasses.ChartMaker.percentageSuccessAX(ChartMaker.java:531)
at testclasses.ChartMaker.main(ChartMaker.java:596)

David Gilbert

Re: Need a sample on MovingAverage

Post by David Gilbert » Wed Feb 26, 2003 12:15 am

There is a demo called MovingAverageDemo in the distribution.

That said, it looks like you have uncovered a bug...can you supply details of your dataset so I can try to reproduce the problem? Or post a small self-contained application that fails with the same error.

Regards,

Dave Gilbert

Amit

Re: Need a sample on MovingAverage

Post by Amit » Wed Feb 26, 2003 3:30 pm

JDBCXYDataset ds = new JDBCXYDataset(DatabaseManager.getConnection());
ds.executeQuery("Select eventdate, (replace(TotalAXSuccess,0,1)/replace(TotalAXReceived,0,1) * 100) as SuccessRate from DailyProcessedQuery");

XYDataset avgds = new MovingAverage().createMovingAverage(ds, "Average", 34, 0);

JFreeChart chart = ChartFactory.createTimeSeriesChart
("AX Success Rate", // Title
"Date", // X-Axis label
"Percentage", // Y-Axis label
avgds, // Dataset
true, // Show legend
true,
true
);


ChartUtilities.saveChartAsPNG(new File("AXPercentageSuccess1.png"), chart, 1000, 600);

} catch (SQLException e) {
e.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}

Amit

Re: Need a sample on MovingAverage

Post by Amit » Wed Mar 05, 2003 8:04 pm

Can anyone please help on this ?

Thanks

David Gilbert

Re: Need a sample on MovingAverage

Post by David Gilbert » Thu Mar 06, 2003 5:36 pm

It is difficult to trace the error because I don't know what is returned by your query.

Regards,

Dave Gilbert

Amit

Re: Need a sample on MovingAverage

Post by Amit » Thu Mar 06, 2003 7:42 pm

Sent you an email with the data returned.

Thanks

Locked