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!
Two Windows, but only the second gets updated?
-
- Posts: 513
- Joined: Wed Sep 12, 2007 3:18 pm
Re: Two Windows, but only the second gets updated?
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.
You may have inadvertently shadowed a variable or incorrectly synchronized access to shared data. As an aside, see this examination of using multiple frames.
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();
Re: Two Windows, but only the second gets updated?
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.
Again, thanks for taking your time and looking into this.

Again, thanks for taking your time and looking into this.
-
- Posts: 2
- Joined: Mon Jan 13, 2020 9:41 pm
- antibot: No, of course not.
Re: Two Windows, but only the second gets updated?
You probably have some static variables and/or functions if you copied the code from one the examples. Get rid of the static stuff.