Two Windows, but only the second gets updated?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).

Two Windows, but only the second gets updated?

Postby dunabur » Mon Oct 09, 2017 7:22 pm

Hey everybody,

I am trying to have multiple windows using JFrame, each being updated as time goes on with more data(using OHLCSeries). The problem is: once I have more then one window (and more then one jfreechart object) open, and I try to update one of those objects with new data, only the last created window gets all the data. So if I have 2 data streams that should go each to one chart, both go to the second/last chart.

Literally all jfreechart code is in one class, and I create multiple instances of that class. I can, for example, set different windows titles, which should be proof that they are independent, but each time I try to update a specific chart instance, only the last created one gets updated.

I'm really confused because I thought each jfreechart instance should be independent of each other, but I can't find any error in my code. Is there something I can do to make those instances independent of each other?

thanks a lot!
dunabur
 
Posts: 13
Joined: Sat Jun 24, 2017 12:05 pm

Re: Two Windows, but only the second gets updated?

Postby John Matthews » Mon Oct 09, 2017 10:35 pm

I can't reproduce your finding. I created two instances of this DynamicTimeSeriesCollection example, and both seem to run independently. Each instance of DTSCTest is a self-contained ApplicationFrame holding a ChartPanel and some controls.

Code: Select all
DTSCTest demo = new DTSCTest(TITLE);
demo.pack();
demo.setLocationByPlatform(true);
demo.setVisible(true);
demo.start();

demo = new DTSCTest(TITLE);
demo.pack();
demo.setLocationRelativeTo(null);
demo.setVisible(true);
demo.start();

You may have inadvertently shadowed a variable or incorrectly synchronized access to shared data. As an aside, see this examination of using multiple frames.
John Matthews
 
Posts: 388
Joined: Wed Sep 12, 2007 3:18 pm

Re: Two Windows, but only the second gets updated?

Postby dunabur » Tue Oct 10, 2017 6:37 pm

Thanks for taking your time. I was baffled that it seemed to be like its the problem with jfreechart. However, I have now finally found out why I had the problem - the OHLCSeries was declared static, and therefore shared between all instances. So it was my error. Really happy about it actually even though its kinda embarrassing. :lol:

Again, thanks for taking your time and looking into this.
dunabur
 
Posts: 13
Joined: Sat Jun 24, 2017 12:05 pm


Return to JFreeChart

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Joshi, Majestic-12 [Bot] and 11 guests