Hello, I'm using OrsonCharts library and it is really amazing, but I have 2 questions.
In my application I use a chart that updates dinamically, but when I add a new value it simply don't update. In JFreechart I used "dataset.setNotify(true)" but here it updates the chart, but fires a null pointer exception in some drawComponent method in Chart3DPanel class. Am I doing something wrong or is there a method that I can call to update the chart safely?
Second: How can I hide the legend?
Thank you in advance!!!
dynamically update
-
- Posts: 5
- Joined: Wed Sep 09, 2015 2:47 pm
- antibot: No, of course not.
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: dynamically update
Please send the stack trace you are seeing and, if possible, a small demo program that illustrates the problem. In general, the update mechanism should work just as in JFreeChart (that is, you update the dataset and all the chart refresh is taken care of automatically).
-
- Posts: 5
- Joined: Wed Sep 09, 2015 2:47 pm
- antibot: No, of course not.
Re: dynamically update
Hello. Ok.
Here is a demo version of the problem. It represents the class that is having problems. In the class, I implement a SerieChangeListener (JFreechart interface) to build 3D points from 3 TimeSeries classes. Each time the series change, a new 3D point is added. In the demo, the exception fires sometimes, but in the program it fires each time a serieChangeEvent is dispatched.
Here is a demo version of the problem. It represents the class that is having problems. In the class, I implement a SerieChangeListener (JFreechart interface) to build 3D points from 3 TimeSeries classes. Each time the series change, a new 3D point is added. In the demo, the exception fires sometimes, but in the program it fires each time a serieChangeEvent is dispatched.
Code: Select all
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.Random;
import javax.swing.JFrame;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.SeriesChangeEvent;
import org.jfree.data.general.SeriesChangeListener;
import org.jfree.data.time.Millisecond;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.time.TimeSeriesDataItem;
import com.orsoncharts.Chart3D;
import com.orsoncharts.Chart3DFactory;
import com.orsoncharts.Chart3DPanel;
import com.orsoncharts.data.xyz.XYZSeries;
import com.orsoncharts.data.xyz.XYZSeriesCollection;
import com.orsoncharts.graphics3d.swing.DisplayPanel3D;
public class Test3d implements SeriesChangeListener {
//3d elements
XYZSeries serie3d = new XYZSeries("Test");
XYZSeriesCollection data3d = new XYZSeriesCollection();
Chart3D chart3d;
DisplayPanel3D panel3d;
JFrame frame3d;
//2d elements
TimeSeries serie2d = new TimeSeries("xAxis");
TimeSeriesCollection data2d = new TimeSeriesCollection();
JFreeChart chart2d;
ChartPanel panel2d;
JFrame frame2d;
double counter = 0;
public static void main(String[] args) {
// TODO Auto-generated method stub
Test3d test = new Test3d();
test.data3d.add(test.serie3d);
test.chart3d = Chart3DFactory.createXYZLineChart("", "", test.data3d, "x", "y", "z");
test.panel3d = new DisplayPanel3D(new Chart3DPanel(test.chart3d));
test.frame3d = new JFrame("3d test");
test.frame3d.getContentPane().add(test.panel3d);
test.frame3d.setPreferredSize(new Dimension(300, 300));
test.data2d.addSeries(test.serie2d);
test.chart2d = ChartFactory.createTimeSeriesChart("", "time", "value", test.data2d);
test.panel2d = new ChartPanel(test.chart2d);
test.frame2d = new JFrame();
test.frame2d.getContentPane().setLayout(new GridBagLayout());
test.frame2d.getContentPane().add(test.panel2d, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5, 5), 0, 0));
test.frame2d.setVisible(true);
test.frame2d.pack();
test.frame3d.setVisible(true);
test.frame3d.pack();
test.serie2d.addChangeListener(test);
test.serie2d.add(new TimeSeriesDataItem(new Millisecond(), 0.5));
try {
Thread.sleep(200);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
while(true) {
test.serie2d.add(new TimeSeriesDataItem(new Millisecond(),(new Random()).nextDouble()));
test.data3d.setNotify(true);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
@Override
public void seriesChanged(SeriesChangeEvent arg0) {
// TODO Auto-generated method stub
serie3d.add(((TimeSeries)arg0.getSource()).getValue(((TimeSeries)arg0.getSource()).getItemCount() - 1).doubleValue(), counter, 0.0);
counter++;
}
}
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: dynamically update
At least in your demo program, the problem appears to be that you are updating the dataset from off the event-dispatch-thread (EDT) (your while loop that updates the dataset is in the main() method, and that runs on it's own thread). It's important to update datasets on the EDT for synchronisation.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- Posts: 5
- Joined: Wed Sep 09, 2015 2:47 pm
- antibot: No, of course not.
Re: dynamically update
Ohhh great. I used a invokeLater() instance and the problem was solved.
Many thanks.
Many thanks.