JFreeChart for JavaFX - Moving Average takes VERY long time

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Post Reply
StealthVice7
Posts: 6
Joined: Sun May 27, 2018 2:05 pm
antibot: No, of course not.

JFreeChart for JavaFX - Moving Average takes VERY long time

Post by StealthVice7 » Sun May 27, 2018 2:37 pm

I am working on a cryptocurrency analysis JavaFX project. One vital part of this program is the chart, which uses fetched data of up to 40,000 ticker points to display a graph with two moving averages.

My program was taking an absurdly long time to display the chart after starting up, sometimes even more than 30 minutes! At first I thought the problem was the renderer (due to me having a lot of data to display), but after changing to the FastXY renderer nothing changed.

I then did some debugging and found that the VAST majority of time was being taken on calculating the moving averages with the createMovingAverage function.

Code: Select all

private XYDataset createDataset() {
    	TimeSeries market;
    	final TimeSeriesCollection dataset = new TimeSeriesCollection();
		try {
			market = actor.marketInfo(180); //smaller better, 240 some number
			System.out.println("done with process");
			final TimeSeries mav = MovingAverage.createMovingAverage(
					market, "5 day moving average", 432000000, 0 // 86400000 is one day
				);
			System.out.println("5 day moving average - done");
		    final TimeSeries mavShort = MovingAverage.createMovingAverage(
		            market, "20 day moving average", 1728000000, 0 // 86400000 is one day
		        );
		    System.out.println("20 day moving average - done");
		    dataset.addSeries(market);
		    dataset.addSeries(mav);
		    dataset.addSeries(mavShort);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return dataset;
    }
Even when I only have 4000 data points, it still may take 5-10 minutes to do the moving average. I think it may have to do with my period I am using for the moving average being so high in milliseconds, but I'm not sure. Anybody have any idea how to speed this up? I may just be misunderstanding something or not configuring things correctly. Thanks in advance.

StealthVice7
Posts: 6
Joined: Sun May 27, 2018 2:05 pm
antibot: No, of course not.

Re: JFreeChart for JavaFX - Moving Average takes VERY long time

Post by StealthVice7 » Wed May 30, 2018 12:16 am

If anybody has any idea how to fix this or if I should just do my own Moving Average calculations I would be very grateful for a reply! :)

John Matthews
Posts: 479
Joined: Wed Sep 12, 2007 3:18 pm

Re: JFreeChart for JavaFX - Moving Average takes VERY long time

Post by John Matthews » Wed May 30, 2018 9:08 am

You could try running the moving average calculation in the background.

StealthVice7
Posts: 6
Joined: Sun May 27, 2018 2:05 pm
antibot: No, of course not.

Re: JFreeChart for JavaFX - Moving Average takes VERY long time

Post by StealthVice7 » Wed May 30, 2018 3:09 pm

What do you mean? How? I'm fairly new to JFreeChart. Do you mean create the chart and display it, and THEN generate Moving Averages and add them to chart?

John Matthews
Posts: 479
Joined: Wed Sep 12, 2007 3:18 pm

Re: JFreeChart for JavaFX - Moving Average takes VERY long time

Post by John Matthews » Wed May 30, 2018 10:00 pm

No; display the chart and then update the moving average TimeSeries in the valueProperty handler of your Task<TimeSeries>.

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

Re: JFreeChart for JavaFX - Moving Average takes VERY long time

Post by david.gilbert » Fri Jun 01, 2018 4:36 am

How is the source series defined? I think there might be a mismatch between the RegularTimePeriod instance used internally by the TimeSeries and the periodCount argument you are using in the call to the method creating the moving average, but it is hard to tell.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Ask your company to buy the JFreeChart Developer Guide
:idea: Check out other products sold by my company Object Refinery Limited

StealthVice7
Posts: 6
Joined: Sun May 27, 2018 2:05 pm
antibot: No, of course not.

Re: JFreeChart for JavaFX - Moving Average takes VERY long time

Post by StealthVice7 » Thu Jun 21, 2018 1:34 am

I am not familiar enough with JFreeChart to fully answer your question, but, my source series is a TimeSeries with each datapoint having a Millisecond from a timestamp and a value of a BigDecimal.

This generated TimeSeries is then returned to my createDataset() method that creates the main line and the two moving averages, both moving averages being based on the main data line, and all three being TimeSeries. I then dataset.addSeries the main line and its two moving averages, with dataset being a TimeSeriesCollection.

createDataset calls actor.marketInfo that returns the TimeSeries of time & value

Code: Select all

private XYDataset createDataset() {
    	TimeSeries market;
    	final TimeSeriesCollection dataset = new TimeSeriesCollection();
		try {
			market = actor.marketInfo(100); //smaller better, 240 some number
			System.out.println("done with process");
			final TimeSeries mavShort = MovingAverage.createMovingAverage(
					market, "5 day moving average", 432000000, 0 // 86400000 is one day
				);
			System.out.println("5 day moving average - done");
		    final TimeSeries mav = MovingAverage.createMovingAverage(
		            market, "20 day moving average", 1728000000, 0 // 86400000 is one day
		        );
		    System.out.println("20 day moving average - done");
		    dataset.addSeries(market);
		    dataset.addSeries(mav);
		    dataset.addSeries(mavShort);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return dataset;
    }
actor.marketInfo

Code: Select all

	TimeSeries marketData = new TimeSeries(currencyPair.toString());

		try {
			...
			{
				...
				BigDecimal close = new BigDecimal((double) ticker.get(4));
				
			    	marketData.addOrUpdate(new Millisecond(timestamp), close);
			}
			
		} catch (ParseException e) {
			e.printStackTrace();
		}

		return marketData;
	}

StealthVice7
Posts: 6
Joined: Sun May 27, 2018 2:05 pm
antibot: No, of course not.

Re: JFreeChart for JavaFX - Moving Average takes VERY long time

Post by StealthVice7 » Sat Jul 14, 2018 2:53 am

Anybody with any idea please respond, I have bumped and deleted for the past month and a half, anything or any form of help is very greatly appreciated.

StealthVice7
Posts: 6
Joined: Sun May 27, 2018 2:05 pm
antibot: No, of course not.

Re: JFreeChart for JavaFX - Moving Average takes VERY long time

Post by StealthVice7 » Fri Jul 20, 2018 2:48 am

Does anybody have any idea? Please?

Post Reply