Hi everyone, I've been working on a project with SWT and JFreeChart. In the program there is a SWT Listbox, when the user click on an item of the listbox,
correspondant data is pulled and displayed with org.jfree.experimental.ChartComposite.
The problem I've occurred to is how to update the ChartComposite properly. It seems neither redraw() or update() would do the job. Though when the Window got resized,
the ChartComposite was updated.
I have tried various ways. The only one worked was by generating a SWT Image object from JFreeChart object and draw it on a Canvas surface. But in this way the chart flicks when
updating. (I know this is more like a SWT question....)
The code snippet is:
....
Image chartImage = null;
Display display = null;
Shell shell = null;
Canvas canvas = null;
SUMMARYFile sum = null;
JFreeChart chart = null;
....
canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
if (chart != null) {
Canvas canvas = (Canvas) e.getSource();
chartImage = createChartImage(canvas, chart, canvas.getBounds().width, canvas.getBounds().height); // routine to generate proper SWT Image object.
e.gc.drawImage(chartImage, 0, 0);
chartImage.dispose();
}
}
});
......
JFreeChart & SWT - How to redraw?
Re: JFreeChart & SWT - How to redraw?
Setting a new Dataset on your JFreeChart's Plot should redraw the ChartComposite.
Re: JFreeChart & SWT - How to redraw?
There's always
or
Might make you happy.
Code: Select all
chartComposite.forceRedraw();
Code: Select all
chartComposite.getChart().fireChartChanged();
-HBro