JFreeChart & SWT - How to redraw?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
DairyKnight
Posts: 1
Joined: Tue May 12, 2009 7:53 am

JFreeChart & SWT - How to redraw?

Post by DairyKnight » Tue May 12, 2009 8:14 am

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();
}
}
});
......

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

Re: JFreeChart & SWT - How to redraw?

Post by beckchr » Sun May 17, 2009 9:25 am

Setting a new Dataset on your JFreeChart's Plot should redraw the ChartComposite.

hbro
Posts: 5
Joined: Mon May 18, 2009 1:27 pm
Location: Retie, Belgium

Re: JFreeChart & SWT - How to redraw?

Post by hbro » Mon May 18, 2009 1:33 pm

There's always

Code: Select all

chartComposite.forceRedraw();
or

Code: Select all

chartComposite.getChart().fireChartChanged();
Might make you happy.
-HBro

Locked