Two Windows, but only the second gets updated?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
dunabur
Posts: 19
Joined: Sat Jun 24, 2017 12:05 pm
antibot: No, of course not.

Two Windows, but only the second gets updated?

Post by 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!

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

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

Post by 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.

dunabur
Posts: 19
Joined: Sat Jun 24, 2017 12:05 pm
antibot: No, of course not.

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

Post by 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.

donj@deltatee.com
Posts: 2
Joined: Mon Jan 13, 2020 9:41 pm
antibot: No, of course not.

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

Post by donj@deltatee.com » Mon Jan 13, 2020 9:45 pm

You probably have some static variables and/or functions if you copied the code from one the examples. Get rid of the static stuff.

Locked