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?
SWT fails to refresh after I add data to chart
-
- Posts: 2
- Joined: Mon Mar 24, 2008 5:43 pm
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
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
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


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.
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.
-
- Posts: 2
- Joined: Mon Mar 24, 2008 5:43 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);
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);