欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

RCP 中调用JFreeChart

程序员文章站 2022-06-14 15:11:04
...
RCP 中调用JFreeChart:
1.

package jfreecharttest;
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.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 = "JFreeChartTest.view";
private static 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;
}
private static JFreeChart createChart(PieDataset dataset)
{
JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 1",
dataset, true,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;
}

public void createPartControl(Composite parent)
{
JFreeChart chart = createChart(createDataset());
final ChartComposite frame = new ChartComposite(parent, SWT.NONE,58 chart, true);
}
public void setFocus() {}
}

相关的Jar包
jcommon-1.0.10.jar
jfreechart-1.0.6.jar
jfreechart-1.0.6-experimental.jar
jfreechart-1.0.6-swt.jar
swtgraphics2d.jar

2. 在Swing中调用JFreeChart, JFreeChart的API中也有相关的JFrame和JPanel.