SWT fails to refresh after I add data to chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
kapostolou
Posts: 2
Joined: Mon Mar 24, 2008 5:43 pm

SWT fails to refresh after I add data to chart

Post by kapostolou » Mon Mar 24, 2008 5:59 pm

I have this RCP program that uses jfreechart.
The way that I create the chart is that I first create the dataset
TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(series);
And then I create the chart
ChartFactory.createTimeSeriesChart(....)
But the dataset are filled by the series that are running in their own thread!
This way at lest in AWT I had the following effect.
The chart is appearing empty at the beginning and then progressively
is filled with data.
Any way the problem is that now in SWT nothing is drawn until I press
a button key on the chart.
Any ideas why this is happening?

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Tue Mar 25, 2008 4:11 am

Possibly a bug in the SWT implementation, which is still experimental. I haven't looked at the SWT code for a while, but hope to give it a good review soon. In the meantime, perhaps you could put together a test case and post a bug report in the tracker at SourceForge?
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Taqua
JFreeReport Project Leader
Posts: 698
Joined: Fri Mar 14, 2003 3:34 pm
Contact:

Post by Taqua » Tue Mar 25, 2008 3:47 pm

Hmm .. to me this sounds like the typical problems you run into if you use the SWT_AWT bridge. Dont use that, use the Swt-specific code in the experimental-directory instead.

And in AWT as well as in SWT, access to threads must be properly shielded. If you copied your AWT code 1-to-1 to SWT, then maybe you are still running the Chart-Updates on the AWT-Event-Dispatcher thread?

AWT and SWT are two different beasts, AWT is Java and SWT is C/C++. They have no connection to each other and use different event-dispatchers. Updating a SWT object from a AWT event-dispatcher is the same as updating it from any other rouge thread - it is just evil.

kapostolou
Posts: 2
Joined: Mon Mar 24, 2008 5:43 pm

Post by kapostolou » Tue Mar 25, 2008 7:55 pm

Well the code that I use goes like this, ( and I don't use the AWT bridge

final TimeSeries series = new TimeSeries(parameter.getName(),
Millisecond.class);

Display display = Display.getCurrent();
if (!(display == null || display.isDisposed())) {
display.asyncExec(new Runnable() {
public void run() {
Job job = new Job(Messages.Chart_ReadFromDataBase)
{
protected IStatus run(IProgressMonitor monitor) {
monitor.beginTask(Messages.Chart_Reading,
IProgressMonitor.UNKNOWN);
try {
ResultSet resultSet = session.getLoggedData(
paramaterID,unitID,startTime, stopTime);
while (resultSet.next()) {
.........
series.add(period, value);


}
resultSet.getStatement().close();
} catch (Exception ex) {}
monitor.done();
return Status.OK_STATUS;
}
};
job.setPriority(Job.SHORT);
job.schedule();
}
});
}

TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(series);
dataset.getDomainBounds(true);

beckchr
Posts: 9
Joined: Wed Feb 28, 2007 2:57 pm

Post by beckchr » Wed Mar 26, 2008 4:57 pm

You are starting the Job from the SWT thread. Why? Instead, you should do the series.add(...) calls in the SWT thread. Try to move the Display.asyncExcec(new Runnable() {}) to just include the series.add() calls.

Locked