Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Getting Charts in the View of Eclipse 3.2
Getting Charts in the View of Eclipse 3.2 [message #178781] Tue, 07 November 2006 13:11 Go to next message
Eclipse UserFriend
Originally posted by:

i was able to write a plugin which added a view with a Pie chart in it. It
worked all fine with eclipse 3.1, but same project is not working in
eclipse 3.2
i know this is not a eclipse help forum but still i will like you to
comment on this.
Thanks in advance

Adding the code for the plugin

package testforreport.views;

//import org.eclipse.swt.widgets.Composite;
import java.awt.Frame;
import java.awt.Panel;

import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.ui.part.*;
import org.eclipse.jface.viewers.*;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.jface.action.*;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.*;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.SWT;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.PlotOrientation;

* This sample class demonstrates how to plug-in a new
* workbench view. The view shows data obtained from the
* model. The sample creates a dummy model on the fly,
* but a real implementation would connect to the model
* available either in this or another plug-in (e.g. the workspace).
* The view is connected to the model using a content provider.
* <p>
* The view uses a label provider to define how model
* objects should be presented in the view. Each
* view can present the same model objects using
* different labels and icons, if needed. Alternatively,
* a single label provider can be shared between views
* in order to ensure that objects of the same type are
* presented in the same way everywhere.
* <p>

public class SampleView extends ViewPart {
private TableViewer viewer;
private Action action1;
private Action action2;
private Action doubleClickAction;

static final FontData titleFD = new FontData("Times", 24, SWT.BOLD);
static final FontData normalFD = new FontData("Times", 12, SWT.NORMAL);
static final FontData headerFD = new FontData("Times", 18, SWT.BOLD);

// private SWTGraphicViewer pieViewer;
// private IChart pieChartModel;

* The content provider class is responsible for
* providing objects to the view. It can wrap
* existing objects in adapters or simply return
* objects as-is. These objects may be sensitive
* to the current input of the view, or ignore
* it and always show the same content
* (like Task List, for example).

class ViewContentProvider implements IStructuredContentProvider {
public void inputChanged(Viewer v, Object oldInput, Object newInput) {
public void dispose() {
public Object[] getElements(Object parent) {
return new String[] { "One", "Two", "Three" };
class ViewLabelProvider extends LabelProvider implements
ITableLabelProvider {
public String getColumnText(Object obj, int index) {
return getText(obj);
public Image getColumnImage(Object obj, int index) {
return getImage(obj);
public Image getImage(Object obj) {
return PlatformUI.getWorkbench().
class NameSorter extends ViewerSorter {

* The constructor.
public SampleView() {

* This is a callback that will allow us
* to create the viewer and initialize it.
public void createPartControl(Composite parent) {
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
viewer.setContentProvider(new ViewContentProvider());
viewer.setLabelProvider(new ViewLabelProvider());
viewer.setSorter(new NameSorter());


//new code start

GridLayout layout = new GridLayout(1, true);
layout.verticalSpacing = 0;
layout.horizontalSpacing = 0;
layout.marginHeight = 0;
layout.marginWidth = 0;
// setLayout(layout);

Composite jFreeComp = new Composite(parent, SWT.EMBEDDED);
jFreeComp.setLayoutData(new GridData(GridData.FILL_VERTICAL |

java.awt.Frame jfreeFrame = SWT_AWT.new_Frame(jFreeComp);

DefaultPieDataset dataset = new DefaultPieDataset();
// XYDataset data = new XYDataset();
dataset.setValue("One", 45);
dataset.setValue("Two", 55);
/* dataset.setValue("Three", 27.5);
dataset.setValue("Four", 17.5);
dataset.setValue("Five", 11.0);
dataset.setValue("Six", 19.4);
JFreeChart chart = ChartFactory.createPieChart(
"Pie Chart Demo 1", // chart title
dataset, // data
false, // include legend
Color backgroundColor = jFreeComp.getBackground();

/* XYDataset data = "" SampleXYDataset2();

JFreeChart chart = ChartFactory.createScatterPlot(
"Scatter Plot",
"X", "Y",
/* Legend legend = chart.getLegend();
if (legend instanceof StandardLegend) {
StandardLegend sl = (StandardLegend) legend;
// NumberAxis domainAxis = (NumberAxis) chart.getXYPlot().getDomainAxis();
// domainAxis.setAutoRangeIncludesZero(false);
ChartPanel chartPanel = new ChartPanel(chart);
/* chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));


//end of new code


private void hookContextMenu() {
MenuManager menuMgr = new MenuManager("#PopupMenu");
menuMgr.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
Menu menu = menuMgr.createContextMenu(viewer.getControl());
getSite().registerContextMenu(menuMgr, viewer);

private void contributeToActionBars() {
IActionBars bars = getViewSite().getActionBars();

private void fillLocalPullDown(IMenuManager manager) {
manager.add(new Separator());

private void fillContextMenu(IMenuManager manager) {
// Other plug-ins can contribute there actions here
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));

private void fillLocalToolBar(IToolBarManager manager) {

private void makeActions() {

action1 = new Action() {
public void run() {
showMessage("Action 1 executed");

action1.setText("Action 1");
action1.setToolTipText("Action 1 tooltip");
action1.setImageDescriptor(PlatformUI.getWorkbench().getShar edImages().

action2 = new Action() {
public void run() {
showMessage("Action 2 executed");
action2.setText("Action 2");
action2.setToolTipText("Action 2 tooltip");
action2.setImageDescriptor(PlatformUI.getWorkbench().getShar edImages().
doubleClickAction = new Action() {
public void run() {
ISelection selection = viewer.getSelection();
Object obj = ((IStructuredSelection)selection).getFirstElement();
showMessage("Double-click detected on "+obj.toString());

private void hookDoubleClickAction() {
viewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {;
private void showMessage(String message) {
"Sample View",

* Passing the focus request to the viewer's control.
public void setFocus() {
Re: Getting Charts in the View of Eclipse 3.2 [message #686005 is a reply to message #178781] Tue, 21 June 2011 11:10 Go to previous messageGo to next message
chinnii  is currently offline chinnii Friend
Messages: 6
Registered: June 2011
Junior Member
Dear Anubhav Pndey,
I have to create an RCP PlugIn Application which renders PieChart.
So i have tried with JFreeChart for SWT.
But when i use this in the View Class of RCP Application it not able to create the View and not Creating PieCharts. I did not change the MANIFEST file. i added all the 7 required JARs in to the Build Path.
Its throwing error like "could not instantiate the view" in the generated view.
And showing the following in the Eclipse Console.
!MESSAGE Unable to create view ID RCPChart.view: Plug-in "RCPChart" was unable to instantiate class "rcpchart.View".
java.lang.NoClassDefFoundError: org/jfree/data/general/PieDataset

I googled the answer but did not get any adequate information.Could you make your precious time for me.I will be waiting for your reply.

Thanks & Regards
Kranti Kumar ch

package rcpchart;

import java.awt.Font;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
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.experimental.chart.swt.ChartComposite;

public class View extends ViewPart {

public void createPartControl(Composite parent) {

JFreeChart chart = createChart(createDataset());
new ChartComposite(parent, SWT.NONE,
chart, true);

public void 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.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
plot.setNoDataMessage("No data available");
return chart;

Re: Getting Charts in the View of Eclipse 3.2 [message #837086 is a reply to message #686005] Thu, 05 April 2012 08:54 Go to previous message
muthunatchiyar ms is currently offline muthunatchiyar msFriend
Messages: 1
Registered: April 2012
Junior Member
i am also facing the same issue.I am able to create view but i am not able to add chart.i am getting the below exception

java.lang.NoClassDefFoundError: org/jfree/data/xy/XYDataset
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(
at java.lang.Class.getConstructor0(
at java.lang.Class.newInstance0(
at java.lang.Class.newInstance(
at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(
at org.eclipse.core.internal.registry.ExtensionRegistry.createExecutableExtension(
at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(
at org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(
at org.eclipse.ui.internal.WorkbenchPlugin.createExtension(
at org.eclipse.ui.internal.registry.ViewDescriptor.createView(
at org.eclipse.ui.internal.ViewReference.createPartHelper(
at org.eclipse.ui.internal.ViewReference.createPart(
at org.eclipse.ui.internal.WorkbenchPartReference.getPart(
at org.eclipse.ui.internal.PartPane.setVisible(
at org.eclipse.ui.internal.ViewPane.setVisible(
at org.eclipse.ui.internal.presentations.PresentablePart.setVisible(
at org.eclipse.ui.internal.presentations.util.TabbedStackPresentation.selectPart(
at org.eclipse.ui.internal.PartStack.refreshPresentationSelection(
at org.eclipse.ui.internal.PartStack.setSelection(
at org.eclipse.ui.internal.PartStack.showPart(
at org.eclipse.ui.internal.PartStack.createControl(
at org.eclipse.ui.internal.PartStack.createControl(
at org.eclipse.ui.internal.PartSashContainer.createControl(
at org.eclipse.ui.internal.PerspectiveHelper.activate(
at org.eclipse.ui.internal.Perspective.onActivate(
at org.eclipse.ui.internal.WorkbenchPage.onActivate(
at org.eclipse.ui.internal.WorkbenchWindow$
at org.eclipse.swt.custom.BusyIndicator.showWhile(
at org.eclipse.ui.internal.WorkbenchWindow.setActivePage(
at org.eclipse.ui.internal.WorkbenchWindow.busyOpenPage(
at org.eclipse.ui.internal.Workbench$21.runWithException(
at org.eclipse.ui.internal.StartupThreading$
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(
at org.eclipse.swt.widgets.Display.runAsyncMessages(
at org.eclipse.swt.widgets.Display.readAndDispatch(
at org.eclipse.ui.application.WorkbenchAdvisor.openWindows(
at org.eclipse.ui.internal.Workbench$28.runWithException(
at org.eclipse.ui.internal.StartupThreading$
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(
at org.eclipse.swt.widgets.Display.runAsyncMessages(
at org.eclipse.swt.widgets.Display.readAndDispatch(
at org.eclipse.ui.internal.Workbench.runUI(
at org.eclipse.ui.internal.Workbench.access$4(
at org.eclipse.ui.internal.Workbench$
at org.eclipse.core.databinding.observable.Realm.runWithDefault(
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(
at testing.Application.start(
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at org.eclipse.equinox.launcher.Main.invokeFramework(
at org.eclipse.equinox.launcher.Main.basicRun(
at org.eclipse.equinox.launcher.Main.main(
Caused by: java.lang.ClassNotFoundException:
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
at java.lang.ClassLoader.loadClassInternal(
... 66 more

i have added all the jars in my build path.
Kindly provide some resolution.
Previous Topic:using Eclipse with java 6 & java 7
Next Topic:Eclipse reduced as Editor
Goto Forum:

Current Time: Mon Jun 25 15:18:28 GMT 2018

Powered by FUDForum. Page generated in 0.03099 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top