RCP中集成jfreechart

一、下载JFreeChart包

1.http://www.jfree.org/jfreechart/ 

 

开发最小依赖包:

  • jcommon-1.0.10.jar

  • jfreechart-1.0.6.jar

  • jfreechart-1.0.6-swt.jar

  •  

    二、View代码如下:

     

     

    package edu.bjtu.port.pieceWage.ui;
    
    import java.awt.BasicStroke;
    import java.awt.Color;
    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.PiePlot3D;
    import org.jfree.chart.title.TextTitle;
    import org.jfree.data.general.DefaultPieDataset;
    import org.jfree.data.general.PieDataset;
    import org.jfree.experimental.chart.swt.ChartComposite;
    import org.jfree.ui.RectangleInsets;
    import org.jport.component.rcp.interfaces.ITableEntity;
    
    public class PieView extends ViewPart {
    	private String titleStr = "" ;
    	
    	public PieView() {
    		super();
    	}
    
    	protected PieDataset createDataset() {
    
    		DefaultPieDataset defaultpiedataset = new DefaultPieDataset();
    		defaultpiedataset.setValue("管理人员", 10.02D);
    		defaultpiedataset.setValue("市场人员", 20.23D);
    		defaultpiedataset.setValue("开发人员", 60.02D);
    		defaultpiedataset.setValue("OEM人员", 10.02D);
    		defaultpiedataset.setValue("其他人员", 5.11D);
    		return defaultpiedataset;
    
    	}
    
    	/**
    	 * Creates a chart.
    	 * @param dataset the dataset.
    	 * @return A chart.
    	 */
    
    	protected JFreeChart createChart(PieDataset dataset) {
    		JFreeChart chart = ChartFactory.createPieChart3D("", dataset, true,
    				true, true);
    		// 设置图片的背景色
    		chart.setBackgroundPaint(java.awt.Color.white);
    		// 设置图片标题的字体和大小
    		Font font = new Font("黑体", Font.CENTER_BASELINE, 20);
    		TextTitle title = new TextTitle(titleStr);
    		title.setFont(font);
    		chart.setTitle(title);
    
    		PiePlot3D pie = (PiePlot3D) chart.getPlot();
    		pie.setInsets(new RectangleInsets(5, 5, 5, 5));
    		// 指定 section 轮廓线的颜色
    		pie.setOutlinePaint(java.awt.Color.BLACK);
    		// 指定 section 轮廓线的厚度
    		pie.setOutlineStroke(new BasicStroke(1));
    		// 设置第一个 section 的开始位置,默认是12点钟方向,90度,逆时针
    		pie.setStartAngle(90);
    		// 指定 section 的色彩
    		pie.setSectionPaint(1, new Color(0x99, 0x99, 0xFF));
    		pie.setLabelFont(new Font("黑体", Font.BOLD, 12));
    		// 指定显示的饼图上圆形还椭圆形。true为圆形,false为椭圆形。默认为false
    		pie.setCircular(true);
    		// 指定图片的透明度
    		pie.setForegroundAlpha(0.5f);
    		pie.setLabelGap(0.01);// 间距
    		pie.setNoDataMessage("No data available");
    		return chart;
    	}
    
    	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() {
    
    	}
    
    	public String getTitleStr() {
    		return titleStr;
    	}
    
    	public void setTitleStr(String titleStr) {
    		this.titleStr = titleStr;
    	}
    }
    

     

    效果如下图:

     

     



     


     

     

    你可能感兴趣的:(eclipse,UI,jfreechart)