Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Dynamic Real-Time chart with JAVA

Posted on 2006-11-24
8
Medium Priority
?
1,319 Views
Last Modified: 2012-08-13
Hi,

I need to create a line chart that needs to show real-time data. So, the data is supposed to be updated in real-time basis and I need to movement of the chart to be visible everytime a new data is added. I tried JFreeChart, though it is quite easy to use and I managed to draw the chart. But, it is not real-time.

Let say I have process that loops 100 times. Each loop will take about 30 seconds to return a value. Then I plot this value to the dataset of the chart. But I couldn't see the chart moving as more values were added. It just showed blank screen until the 100th loop, then it showed all the values at one go. For JFreeChart, everytime we added new value, the entire chart is redrawn again from scratch, it is not really suitable for real-time charting.

Does anybody have a better recommendation or solution on this?


Regards,
rospcc
0
Comment
Question by:rospcc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
8 Comments
 
LVL 16

Accepted Solution

by:
suprapto45 earned 1000 total points
ID: 18008682
In my opinion,

Either you reload your chart in specified time (30 seconds) using scheduler such as Quartz or using Trigger in your DB (assuming that your DB supports Trigger) to execute your Servlet or etc or another thing is to use AJAX but would be complex.

Just my thoughts

David
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 18009055
> the entire chart is redrawn again from scratch
That doesn't reduce performance if you update the chart once per second
Simulating a completely real time projection will put the cpu under pressure and is not recommended at all
0
 

Author Comment

by:rospcc
ID: 18013442
Sorry, I forgot to mention that the application is just purely java and swing. There is no servlet, jsp or ajax needed. Probably it will help you guys to have a clearly picture of what I'm trying to do. I'm writing an optimisation program using genetic algorithms (GA) to solve a tsp and load distribution problem. So, everytime the GA method is called, it will return a value, what we call "Fitness Value". This value has to be displayed on a chart. The looping normally ranges from 500 to unlimited times till it returns the best solution or no more improvement. I want the chart to show the value started from loop 1 till the end.

At first, I drew the chart in a JPanel. Then, everytime GA returned the value, I updated the chart dataset. But my problem with this is the chart couldn't be seen until the last looping. It the chart can only be seen when the process ended, then I might as well just stored the fitness values in a container. When it is completed, I plot the chart with the entire container.

I'm aware that it will reduce the performance. The chart is just an extra feature. The main concern on the performance is on the GA section.


Cheers,
rospcc
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 14

Expert Comment

by:hoomanv
ID: 18013482
What about updating the chart at regular time intervals ? Say once per second. So it would have enough time to generate the next frame.
0
 

Author Comment

by:rospcc
ID: 18024969
Updating the chart at regular time intervals? Does this mean that if I set the interval to be 1 minute and the GA function returns 3 values in 1 minute, the chart will be updated 3 values at a time? Can't we make it looks like those in stock market?

Will it work if we use the actionListener to listen for the dataset changes and update the dataset under actionPerformed?


rospcc
0
 
LVL 14

Assisted Solution

by:hoomanv
hoomanv earned 1000 total points
ID: 18029865
The values may arrive all at once or they may arrive at long intervals
So its all up to you, whether the arrival rate is high or low you should make the refresh rate manageable by user
Even Its good to let the user disable the auto-refresh and he would refresh it manually whenever desired

> update the dataset under actionPerformed
This would raise the problem where a lot of changes are arriving at once and the chart gets regenerated for each new value, so it'll cease to function on high rate circumstances. Therefore its highly recommended that you don't hurriedly redraw the graph after each new value has come, because there could be incoming values that may arrive soon. Just waiting to collect more updates and output them all together is more efficient
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question