Solved

Dynamic Real-Time chart with JAVA

Posted on 2006-11-24
8
1,311 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
  • 3
  • 2
8 Comments
 
LVL 16

Accepted Solution

by:
suprapto45 earned 250 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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 250 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
java stored proc example 9 45
How  can  i  resolve  HTTP Status 404 -? 8 44
ejb mdb examples 1 8
American Express @Work site and Java 4 28
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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:

829 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