Bug - AutoRange in TimeSeriesChart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
MartinL
Posts: 4
Joined: Wed Feb 15, 2012 10:12 am
antibot: No, of course not.

Bug - AutoRange in TimeSeriesChart

Post by MartinL » Wed Feb 15, 2012 12:29 pm

Hi,

I want to report this bug. It occures about 5-10 Times every hour when updating my DataSet every Minute.

Here is a Demo:
http://tinyurl.com/AutoRangeBug
Image

It seems, like it saves the wrong maxY value and uses only the second last value.


Regards,

Martin

matinh
Posts: 483
Joined: Fri Aug 11, 2006 10:08 am
Location: Austria

Re: Bug - AutoRange in TimeSeriesChart

Post by matinh » Wed Feb 15, 2012 2:52 pm

MartinL wrote:I want to report this bug. It occures about 5-10 Times every hour when updating my DataSet every Minute.
Which bug?

Please do at least describe what it does and what you expect.

- martin

MartinL
Posts: 4
Joined: Wed Feb 15, 2012 10:12 am
antibot: No, of course not.

Re: Bug - AutoRange in TimeSeriesChart

Post by MartinL » Wed Feb 15, 2012 3:56 pm

I have turned on AutoRange. It should set the range automatically from minimum value to maximum value.
Instead of getting the right maximum value (18000) it takes (probably) the second last value (3000).
So it cuts off the part above 3000.
I add my values over time, every 1 minute for 60 minutes. And my second last value changes
Check my Demo.

before adding a value:
Image
after updating last value + adding another value:
Image

MartinL
Posts: 4
Joined: Wed Feb 15, 2012 10:12 am
antibot: No, of course not.

Re: Bug - AutoRange in TimeSeriesChart

Post by MartinL » Mon Feb 20, 2012 10:51 am

bump.

Any updates on that?

I guess the problem is in the addAndUpdate() function. The maxY value is set wrong after changing the last value and adding another one.

Regards,

MartinL

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

Re: Bug - AutoRange in TimeSeriesChart

Post by John Matthews » Mon Feb 20, 2012 6:19 pm

You might compare your approach to the example discussed here:
Using JFreeChart to display recent changes in a time series.

steveb
Posts: 4
Joined: Wed Jun 13, 2012 1:30 pm
antibot: No, of course not.

Re: Bug - AutoRange in TimeSeriesChart

Post by steveb » Wed Dec 05, 2012 6:58 pm

I am seeing the same kind of problem with 'autorange' and a timeseries. In this case, the autorange does not see a value if it is for a Day added into an existing series, after a 'within-range' point has been added for the same Day.

I haven't seen a workaround in related questions. Once the range-extending point has been missed, it does not get recognized by further 'fireSeriesChange' or zoom-in/restore zoom operations.

A sample program showing the problem. The chart should display, then add another point after 3 seconds which will be off of the top of the plotted data area:

Code: Select all

import javax.swing.JFrame;
import javax.swing.JPanel;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.time.Day;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;

/**
 * Demonstrate the problem showing up trying to use autorange.
 */
public class DemoAutoRangeProblem extends JPanel {
	
	private final JFreeChart mChart;
	
	public DemoAutoRangeProblem() {
		mChart = buildChart();
		add(new ChartPanel(mChart));
		addData();
	}
	
	/** Build a chart with for values in a timeseries */
	private JFreeChart buildChart() {
		DateAxis xaxis = new DateAxis("Date");
		NumberAxis yaxis = new NumberAxis("Count");
		yaxis.setAutoRange(true);
		XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, true);
		TimeSeriesCollection dataset = new TimeSeriesCollection();
		XYPlot plot = new XYPlot(dataset, xaxis, yaxis, renderer);
		
		JFreeChart chart = new JFreeChart("Demo Autorange Problem", plot);
		return chart;
	}
	
	/** Create some initial data */
	private void addData() {
		TimeSeries series = new TimeSeries("Count");
		series.add(new Day(20, 8, 2012), 5);
		series.add(new Day(21, 8, 2012), 2);
		series.add(new Day(22, 8, 2012), 10);
		((TimeSeriesCollection) mChart.getXYPlot().getDataset()).addSeries(series);
	}
	
	/** Add more data points, going above the existing range */
	public void addMoreData() {
		TimeSeriesCollection dataset0 = (TimeSeriesCollection) mChart.getXYPlot().getDataset(0);
		TimeSeries series = dataset0.getSeries(0);
		//
		// if add a point within the current range,
		// and then adding a value at same day but above the range,
		// the 'auto-range' does not see the higher value.
		//
		series.addOrUpdate(new Day(23, 8, 2012), 8);
		series.addOrUpdate(new Day(23, 8, 2012), 19);
	}

	/** Show the demo chart */
	public static void main(String[] args) {
		DemoAutoRangeProblem gui = new DemoAutoRangeProblem();
		
		JFrame f = new JFrame("Demo of autorange problem");
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.setContentPane(gui);
		f.pack();
		f.setVisible(true);

		// waiting until chart is displayed, then adding more data points
		try {Thread.sleep(3000);} catch (InterruptedException e) {;}
		gui.addMoreData();
	}
}
thanks,
Steve

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

Re: Bug - AutoRange in TimeSeriesChart

Post by John Matthews » Fri Dec 07, 2012 4:29 am

I see a similar result with this variation that updates day three of a time series each time a button is pressed.

Image

Code: Select all

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.util.Random;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.time.Day;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;

/**
 * Demonstrate a problem using auto-range.
 */
public class DemoAutoRangeProblem extends JPanel {

    private static final Random r = new Random();
    private TimeSeriesCollection dataset = new TimeSeriesCollection();
    private DateAxis xaxis = new DateAxis("Date");
    private NumberAxis yaxis = new NumberAxis("Count");

    public DemoAutoRangeProblem() {
        addData();
        yaxis.setAutoRange(true);
        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, true);
        XYPlot plot = new XYPlot(dataset, xaxis, yaxis, renderer);
        JFreeChart chart = new JFreeChart("Demo Autorange Problem", plot);
        ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setMouseWheelEnabled(true);
        add(chartPanel);
    }

    /**
     * Create a 3 day chart
     */
    private void addData() {
        TimeSeries series = new TimeSeries("Count");
        series.add(new Day(1, 8, 2012), -1);
        series.add(new Day(2, 8, 2012), 1);
        series.add(new Day(3, 8, 2012), 0);
        dataset.addSeries(series);
    }

    /**
     * Replace day 3 with a random value
     */
    public void replaceDay3() {
        TimeSeries series = dataset.getSeries(0);
        series.addOrUpdate(new Day(3, 8, 2012), r.nextGaussian());
        System.out.println(yaxis.getRange());
    }

    /**
     * Show the demo chart
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                final DemoAutoRangeProblem gui = new DemoAutoRangeProblem();
                JFrame f = new JFrame("Demo of autorange problem");
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                gui.add(new JButton(new AbstractAction("Add") {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        gui.replaceDay3();
                    }
                }));
                f.add(gui);
                f.pack();
                f.setVisible(true);
            }
        });
    }
}

maxo
Posts: 3
Joined: Fri Mar 01, 2013 10:12 am
antibot: No, of course not.

Re: Bug - AutoRange in TimeSeriesChart

Post by maxo » Fri Mar 01, 2013 10:21 am

I'm running into a similar issue. I took a quick look through the code, and it seems like there might be a bug in org.jfree.data.time.TimeSeries. In the addOrUpdate() method, the following code is updating the minY and maxY:

Code: Select all

else if (item.getValue() != null) {
                double yy = item.getValue().doubleValue();
                this.minY = minIgnoreNaN(this.minY, yy);
                this.maxY = minIgnoreNaN(this.maxY, yy);
}
I think the maxY is being set incorrectly.

maxo
Posts: 3
Joined: Fri Mar 01, 2013 10:12 am
antibot: No, of course not.

Re: Bug - AutoRange in TimeSeriesChart

Post by maxo » Fri Mar 01, 2013 1:06 pm

I made the following code change to the snippet from my previous post and rebuilt. It fixed the range problem.

Code: Select all

else if (item.getValue() != null) {
                double yy = item.getValue().doubleValue();
                this.minY = minIgnoreNaN(this.minY, yy);
                this.maxY = maxIgnoreNaN(this.maxY, yy);
}

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

Re: Bug - AutoRange in TimeSeriesChart

Post by John Matthews » Sun Mar 03, 2013 8:59 am


uli
Posts: 24
Joined: Sat Mar 14, 2009 3:22 pm
Location: Berlin

Re: Bug - AutoRange in TimeSeriesChart

Post by uli » Wed Mar 13, 2013 6:02 pm

Great! I also noticed this problem and I'm happy that it is solved (already on 2011-12-03 as I saw in the commit).

But there comes a stupid question to me: How can I get the updated jar files?
Downloading the jfreechart-1.0.14.zip from sourceforge gives me still the version from 2011-11-20.

Do I need to connect to the repository somehow?

Regards,
Julia

kkonkler
Posts: 3
Joined: Wed Mar 13, 2013 7:23 pm
antibot: No, of course not.

Re: Bug - AutoRange in TimeSeriesChart

Post by kkonkler » Wed Mar 13, 2013 7:38 pm

I too am happy that this is solved and have the same question as Julia.

Will there be a 1.0.15 release with this fix sometime soon?

matinh
Posts: 483
Joined: Fri Aug 11, 2006 10:08 am
Location: Austria

Re: Bug - AutoRange in TimeSeriesChart

Post by matinh » Thu Mar 14, 2013 8:39 am

Hi!

You have three possibilities:
  1. either you checkout JFreeChart from it's source repository (which is described on this wiki page).
  2. or use a 1.0.15-SNAPSHOT from this maven repository.
  3. or wait for the 1.0.15 release to happen. But please don't ask when it is expected ;-)
hth,
- martin

kkonkler
Posts: 3
Joined: Wed Mar 13, 2013 7:23 pm
antibot: No, of course not.

Re: Bug - AutoRange in TimeSeriesChart

Post by kkonkler » Thu Mar 14, 2013 8:34 pm

Thanks!

Locked