Bug - AutoRange in TimeSeriesChart
Bug - AutoRange in TimeSeriesChart
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
It seems, like it saves the wrong maxY value and uses only the second last value.
Regards,
Martin
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
It seems, like it saves the wrong maxY value and uses only the second last value.
Regards,
Martin
Re: Bug - AutoRange in TimeSeriesChart
Which bug?MartinL wrote:I want to report this bug. It occures about 5-10 Times every hour when updating my DataSet every Minute.
Please do at least describe what it does and what you expect.
- martin
Re: Bug - AutoRange in TimeSeriesChart
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:
after updating last value + adding another 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:
after updating last value + adding another value:
Re: Bug - AutoRange in TimeSeriesChart
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
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
-
- Posts: 513
- Joined: Wed Sep 12, 2007 3:18 pm
Re: Bug - AutoRange in TimeSeriesChart
You might compare your approach to the example discussed here:
Using JFreeChart to display recent changes in a time series.
Using JFreeChart to display recent changes in a time series.
Re: Bug - AutoRange in TimeSeriesChart
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:
thanks,
Steve
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();
}
}
Steve
-
- Posts: 513
- Joined: Wed Sep 12, 2007 3:18 pm
Re: Bug - AutoRange in TimeSeriesChart
I see a similar result with this variation that updates day three of a time series each time a button is pressed.
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);
}
});
}
}
Re: Bug - AutoRange in TimeSeriesChart
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:
I think the maxY is being set incorrectly.
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);
}
Re: Bug - AutoRange in TimeSeriesChart
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);
}
-
- Posts: 513
- Joined: Wed Sep 12, 2007 3:18 pm
Re: Bug - AutoRange in TimeSeriesChart
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
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
Re: Bug - AutoRange in TimeSeriesChart
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?
Will there be a 1.0.15 release with this fix sometime soon?
Re: Bug - AutoRange in TimeSeriesChart
Hi!
You have three possibilities:
- martin
You have three possibilities:
- either you checkout JFreeChart from it's source repository (which is described on this wiki page).
- or use a 1.0.15-SNAPSHOT from this maven repository.
- or wait for the 1.0.15 release to happen. But please don't ask when it is expected
- martin