refreshing JFreeChart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
debolina
Posts: 4
Joined: Fri Dec 15, 2006 6:32 pm

refreshing JFreeChart

Post by debolina » Mon Dec 18, 2006 3:57 pm

I am using the code that I have posted below to add JFreeChart into an eclipse RCP application.
I have the problem that I cannot refresh the chart.
I tried using refresh buffer on the frame but that does not work.
I tried to dispose off the composite also before I run the program again to create the chart.
That refershes the chart the first time I rerun the program only.
Does anybody have any idea about what the problem can be?


/// STEP 1 ////////////////////////////////////////////////
// create a composite suitable for displaying all of our chart data
Composite chartComposite = new Composite(/* options */);
chartComposite.setLayoutData(/* set the layout options */);

/// STEP 2 ////////////////////////////////////////////////
// create the dataset for the pie chart of the distribution
DefaultPieDataset pieData = new DefaultPieDataset();
/* populate the pieData here */

JFreeChart chart = ChartFactory.createPie3DChart(/* some options */);
// OPTIONAL: tinkering with plot options here

/// STEP 3 ////////////////////////////////////////////////
// Grab the background color from the SWT Composite
// so our AWT panel "matches" the SWT Composite
Color backgroundColor = chartComposite.getBackground();

// create the frame
Frame chartFrame = SWT_AWT.new_Frame(chartComposite);


chartPanel.setLayout(/* some AWT/Swing layout manager like BoxLayout */);

/// STEP 4 ////////////////////////////////////////////////
ChartPanel jfreeChartPanel = new ChartPanel(chart);
chartpanel.setRefreshBuffer(true);
chartPanel.add(jfreeChartPanel);

Thanks for any help.

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

Post by Taqua » Mon Dec 18, 2006 6:33 pm

The SWT-to-AWT bridge is no way to retain your sanity. It is complicated (if not buggy) and passign events from one framework to another is ... at least difficult.

Why dont you try the native SWT classes that are contained in JFreeChart. In the CVS (and maybe also in the download) there's a directory called 'swt', which contains native SWT components for the charting. You have to compile them by yourself, but after that you could get rid of the Swing-based ChartPanel and the refresh problem.

(On the other hand: Try to disable the double-buffering on the ChartPanel, maybe this already helps.)

Regards,
Thomas

debolina
Posts: 4
Joined: Fri Dec 15, 2006 6:32 pm

refresh JfreeChart

Post by debolina » Mon Dec 18, 2006 7:48 pm

Without using the SWT_AWT bidge can I actually embedd a chart into a RCP application ?

heprom
Posts: 91
Joined: Sat May 27, 2006 4:25 am
Location: Paris

Post by heprom » Wed Dec 20, 2006 10:18 am

Yes you can, it is pretty simple once you've compiled the code:

Code: Select all

ChartComposite chartComposite = new ChartComposite(parent,SWT.NONE,chart,true);
The ChartComposite is a SWT Composite object...

on the other hand you should be able to get the SWT_AWT bridge working. Try some examples given on the forum.

s.eggers
Posts: 6
Joined: Fri Nov 10, 2006 8:25 am

Post by s.eggers » Wed Feb 28, 2007 9:23 am

Hi, I have almost the same problem. If I redraw a Chart the Chart does not fill the SWT Composite anymore. I tried a lot of redraw and pack instructions but they all did not work. The only thing thats works is to maximize the whole shell. But that is not a good workaround.

Can anybody help?

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

Post by beckchr » Wed Feb 28, 2007 3:08 pm

Hi, I had the same problem. I guess this is a bug in the ChartComposite class. I solved it by changing method

Code: Select all

public void chartChanged(ChartChangeEvent event)
:
Replace

Code: Select all

this.redraw();
by

Code: Select all

this.forceRedraw();
As an alternative to direcly hacking ChartComposite you may want to subclass and overrid method chartChanged().

s.eggers
Posts: 6
Joined: Fri Nov 10, 2006 8:25 am

Post by s.eggers » Wed Feb 28, 2007 3:40 pm

I think you are using the experimental code of JFreeChart right? I am using the SWT_AWT class of eclipse to use JFreeChart in SWT. I don't like to use the experimental code of JFreeChart because of the Font Size Problems. Any idea what i could do there to force a redraw?

Regards

Locked