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.
refreshing JFreeChart
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
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
refresh JfreeChart
Without using the SWT_AWT bidge can I actually embedd a chart into a RCP application ?
Yes you can, it is pretty simple once you've compiled the code:
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.
Code: Select all
ChartComposite chartComposite = new ChartComposite(parent,SWT.NONE,chart,true);
on the other hand you should be able to get the SWT_AWT bridge working. Try some examples given on the forum.
Hi, I had the same problem. I guess this is a bug in the ChartComposite class. I solved it by changing method
:
Replace
by
As an alternative to direcly hacking ChartComposite you may want to subclass and overrid method chartChanged().
Code: Select all
public void chartChanged(ChartChangeEvent event)
Replace
Code: Select all
this.redraw();
Code: Select all
this.forceRedraw();