Troubleshooting Random Errors when Changing Series Using JFreeChart
Introduction
This discussion addresses issues encountered when attempting to dynamically update a JFreeChart dataset by adding and removing series. The goal is to visualize changing data points over time without relying on a time-based X-axis or using the DynamicTimeSeriesCollection.
Issues and Resolution
The provided code attempts to update the dataset by repeatedly adding and removing a series, but this approach is incorrect. Instead, the dataset should be updated within the process() method of a SwingWorker.
Additionally, to create a chart with a domain based on iteration count rather than time, use a NumberAxis instead of a DateAxis.
Example Code
The following code snippet demonstrates how to track the progress of a computation using a line chart:
private XYSeries series = new XYSeries("Result"); … @Override protected void process(List<Double> chunks) { for (double d : chunks) { label.setText(df.format(d)); series.add(++n, d); } }
The graph will automatically update as the computation progresses.
Additional Considerations
The above is the detailed content of How to Troubleshoot Dynamic JFreeChart Series Updates Without a Time-Based Axis?. For more information, please follow other related articles on the PHP Chinese website!