6
我想喲在RCP應用程序中使用JFreeChart與簡單的看法。我將JfreeChart jar文件添加爲項目引用的庫。Eclipse RCP與JFreeChart
視圖不能因爲錯誤的創建:
Could not create the view: Plug-in "ViewJFreeChart" was unable to instantiate class "viewJFreeChart.View".
java.lang.NoClassDefFoundError: org/jfree/data/general/PieDataset
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
......
這是View.java源代碼:
package viewJFreeChart;
import java.awt.Font;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
import org.jfree.experimental.chart.swt.ChartComposite;
public class View extends ViewPart {
public static final String ID = "ViewJFreeChart.view";
private TableViewer viewer;
/**
* This is a callback that will allow us to create the viewer and initialize
* it.
*/
public void createPartControl(Composite parent) {
JFreeChart chart = createChart(createDataset());
final ChartComposite frame = new ChartComposite(parent, SWT.NONE,
chart, true);
}
/**
* Passing the focus request to the viewer's control.
*/
public void setFocus() {
viewer.getControl().setFocus();
}
/**
* Creates the Dataset for the Pie chart
*/
private PieDataset createDataset() {
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("One", new Double(43.2));
dataset.setValue("Two", new Double(10.0));
dataset.setValue("Three", new Double(27.5));
dataset.setValue("Four", new Double(17.5));
dataset.setValue("Five", new Double(11.0));
dataset.setValue("Six", new Double(19.4));
return dataset;
}
/**
* Creates the Chart based on a dataset
*/
private JFreeChart createChart(PieDataset dataset) {
JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 1", // chart
// title
dataset, // data
true, // include legend
true, false);
PiePlot plot = (PiePlot) chart.getPlot();
plot.setSectionOutlinesVisible(false);
plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
plot.setNoDataMessage("No data available");
plot.setCircular(false);
plot.setLabelGap(0.02);
return chart;
}
}
謝謝。它將JFreeChart庫添加到Manifest的類路徑後起作用。 – penguru 2009-10-02 08:55:02
不客氣,欲瞭解更多信息,請參閱有關RCP應用程序的3部分教程:http://www.eclipse.org/articles/Article-RCP-1/ tutorial1.html – 2009-10-02 09:22:17
很好地放和說明,像往常一樣。 +1 – VonC 2009-10-02 10:47:56