import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.Panel;
import javax.swing.JRootPane;
import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
import org.jfree.util.Rotation;
public class PieChart3DDemo3 {
protected Shell shell;
/**
* Launch the application.
*
* @param args
*/
public static void main(String[] args) {
try {
PieChart3DDemo3 window = new PieChart3DDemo3();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Open the window.
*/
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
/**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
shell.setSize(480, 400);
shell.setText("PieChart3DDemo3");
shell.setLayout(new FillLayout(SWT.HORIZONTAL));
Composite composite = new Composite(shell, SWT.EMBEDDED);
Frame frame = SWT_AWT.new_Frame(composite);
Panel panel = new Panel();
frame.add(panel);
panel.setLayout(new BorderLayout(0, 0));
JRootPane rootPane = new JRootPane();
panel.add(rootPane);
PieDataset dataset = createSampleDataset();
JFreeChart chart = createChart(dataset);
ChartPanel chartPanel = new ChartPanel(chart);
panel.add(chartPanel);
}
private PieDataset createSampleDataset() {
DefaultPieDataset result = new DefaultPieDataset();
result.setValue("Java", new Double(43.2));
result.setValue("Visual Basic", new Double(10.0));
result.setValue("C/C++", new Double(17.5));
result.setValue("PHP", new Double(32.5));
result.setValue("Perl", new Double(1.0));
return result;
}
private JFreeChart createChart(final PieDataset dataset) {
JFreeChart chart = ChartFactory.createPieChart3D("Pie Chart 3D Demo 3",
dataset, true, true, true);
PiePlot3D plot = (PiePlot3D) chart.getPlot();
plot.setStartAngle(0);
plot.setDirection(Rotation.ANTICLOCKWISE);
plot.setForegroundAlpha(0.5f);
plot.setNoDataMessage("No data to display");
plot.setLabelGenerator(null);
return chart;
}
}