SWT中使用JFreechart(例子)

  1 None.gif package  com.glnpu.dmp.test;
  2 None.gif
  3 None.gif import  java.awt.Color;
  4 None.gif import  java.awt.Font;
  5 None.gif import  java.awt.Frame;
  6 None.gif import  java.util.Calendar;
  7 None.gif import  java.util.Date;
  8 None.gif
  9 None.gif import  org.eclipse.jface.window.ApplicationWindow;
 10 None.gif import  org.eclipse.swt.SWT;
 11 None.gif import  org.eclipse.swt.awt.SWT_AWT;
 12 None.gif import  org.eclipse.swt.graphics.Point;
 13 None.gif import  org.eclipse.swt.widgets.Composite;
 14 None.gif import  org.eclipse.swt.widgets.Control;
 15 None.gif import  org.eclipse.swt.widgets.Display;
 16 None.gif import  org.eclipse.swt.widgets.Shell;
 17 None.gif import  org.eclipse.swt.widgets.TabFolder;
 18 None.gif import  org.eclipse.swt.widgets.TabItem;
 19 None.gif import  org.jfree.chart.ChartFactory;
 20 None.gif import  org.jfree.chart.ChartPanel;
 21 None.gif import  org.jfree.chart.JFreeChart;
 22 None.gif import  org.jfree.chart.plot.PiePlot;
 23 None.gif import  org.jfree.chart.title.TextTitle;
 24 None.gif import  org.jfree.data.category.IntervalCategoryDataset;
 25 None.gif import  org.jfree.data.gantt.Task;
 26 None.gif import  org.jfree.data.gantt.TaskSeries;
 27 None.gif import  org.jfree.data.gantt.TaskSeriesCollection;
 28 None.gif import  org.jfree.data.general.DefaultPieDataset;
 29 None.gif
 30 ExpandedBlockStart.gifContractedBlock.gif public   class  Test  extends  ApplicationWindow  dot.gif {
 31InBlock.gif
 32ExpandedSubBlockStart.gifContractedSubBlock.gif    /** *//**
 33InBlock.gif     * Create the application window
 34ExpandedSubBlockEnd.gif     */

 35ExpandedSubBlockStart.gifContractedSubBlock.gif    public Test() dot.gif{
 36InBlock.gif        super(null);
 37InBlock.gif        addToolBar(SWT.FLAT | SWT.WRAP);
 38InBlock.gif        addMenuBar();
 39InBlock.gif        addStatusLine();
 40ExpandedSubBlockEnd.gif    }

 41InBlock.gif
 42ExpandedSubBlockStart.gifContractedSubBlock.gif    /** *//**
 43InBlock.gif     * Create contents of the application window
 44InBlock.gif     * 
 45InBlock.gif     * @param parent
 46ExpandedSubBlockEnd.gif     */

 47InBlock.gif    @Override
 48ExpandedSubBlockStart.gifContractedSubBlock.gif    protected Control createContents(Composite parent) dot.gif{
 49InBlock.gif        TabFolder tf = new TabFolder(parent, SWT.TOP);
 50InBlock.gif        TabItem ti = new TabItem(tf, SWT.NULL);
 51InBlock.gif        ti.setText("分类");
 52InBlock.gif        Composite composite = new Composite(tf, SWT.NO_BACKGROUND
 53InBlock.gif                | SWT.EMBEDDED);
 54InBlock.gif        Frame frame = SWT_AWT.new_Frame(composite);
 55InBlock.gif        frame.add(new ChartPanel(createBarChart()));
 56InBlock.gif        ti.setControl(composite);
 57InBlock.gif        TabItem ti1 = new TabItem(tf, SWT.NULL);
 58InBlock.gif        ti1.setText("项目组");
 59InBlock.gif        Composite composite1 = new Composite(tf, SWT.NO_BACKGROUND
 60InBlock.gif                | SWT.EMBEDDED);
 61InBlock.gif        Frame frame1 = SWT_AWT.new_Frame(composite1);
 62InBlock.gif        frame1.add(new ChartPanel(createGanttChart()));
 63InBlock.gif        ti1.setControl(composite1);
 64InBlock.gif        tf.setSelection(0);
 65InBlock.gif        return tf;
 66ExpandedSubBlockEnd.gif    }

 67InBlock.gif
 68ExpandedSubBlockStart.gifContractedSubBlock.gif    /** *//**
 69InBlock.gif     * 方法名称: 内容摘要:
 70InBlock.gif     * 
 71InBlock.gif     * @return
 72InBlock.gif     * @return JFreeChart
 73InBlock.gif     * @throws
 74ExpandedSubBlockEnd.gif     */

 75ExpandedSubBlockStart.gifContractedSubBlock.gif    private JFreeChart createGanttChart() dot.gif{
 76InBlock.gif        String title = "Gantt测试";
 77InBlock.gif        IntervalCategoryDataset dataset = createSampleDataset();
 78InBlock.gif
 79InBlock.gif        JFreeChart jfc = ChartFactory.createGanttChart(title, "项目各阶段详细实施计划",
 80InBlock.gif                "项目周期", dataset, falsefalsefalse);
 81InBlock.gif
 82InBlock.gif        return jfc;
 83ExpandedSubBlockEnd.gif    }

 84InBlock.gif
 85ExpandedSubBlockStart.gifContractedSubBlock.gif    /** *//**
 86InBlock.gif      * 方法名称:
 87InBlock.gif      * 内容摘要:创建gantt内容
 88InBlock.gif      *
 89InBlock.gif      * @return
 90InBlock.gif      * @return IntervalCategoryDataset
 91InBlock.gif      * @throws
 92ExpandedSubBlockEnd.gif     */

 93ExpandedSubBlockStart.gifContractedSubBlock.gif    private IntervalCategoryDataset createSampleDataset() dot.gif{
 94InBlock.gif        TaskSeries s1 = new TaskSeries("日程表");
 95InBlock.gif
 96InBlock.gif        Task t1 = new Task("项目立项", date(1, Calendar.APRIL, 2001), date(5,
 97InBlock.gif                Calendar.APRIL, 2001));
 98InBlock.gif        t1.setPercentComplete(1.00);
 99InBlock.gif        
100InBlock.gif        Task t2 = new Task("项目立项讨论", date(6, Calendar.APRIL, 2001), date(19,
101InBlock.gif                Calendar.APRIL, 2001));
102InBlock.gif        
103InBlock.gif        s1.add(t1);
104InBlock.gif        s1.add(t2);
105InBlock.gif        
106InBlock.gif        
107InBlock.gif        final Task t3 = new Task(
108InBlock.gif                "需求分析"
109InBlock.gif                date(10, Calendar.APRIL, 2001), date(5, Calendar.MAY, 2001)
110InBlock.gif            );
111InBlock.gif            final Task st31 = new Task(
112InBlock.gif                "需求1"
113InBlock.gif                date(10, Calendar.APRIL, 2001), date(25, Calendar.APRIL, 2001)
114InBlock.gif            );
115InBlock.gif            st31.setPercentComplete(1.0);
116InBlock.gif            final Task st32 = new Task(
117InBlock.gif                "需求2"
118InBlock.gif                date(1, Calendar.MAY, 2001), date(5, Calendar.MAY, 2001)
119InBlock.gif            );
120InBlock.gif            st32.setPercentComplete(1.0);
121InBlock.gif            t3.addSubtask(st31);
122InBlock.gif            t3.addSubtask(st32);
123InBlock.gif            s1.add(t3);
124InBlock.gif        
125InBlock.gif        
126InBlock.gif        
127InBlock.gif        final TaskSeriesCollection collection = new TaskSeriesCollection();
128InBlock.gif        collection.add(s1);
129InBlock.gif
130InBlock.gif        return collection;
131ExpandedSubBlockEnd.gif    }

132InBlock.gif
133ExpandedSubBlockStart.gifContractedSubBlock.gif    /** *//** */
134ExpandedSubBlockStart.gifContractedSubBlock.gif    /** *//**
135InBlock.gif     * Utility method for creating <code>Date</code> objects.
136InBlock.gif     * 
137InBlock.gif     * @param day
138InBlock.gif     *            日
139InBlock.gif     * @param month
140InBlock.gif     *            月
141InBlock.gif     * @param year
142InBlock.gif     *            年
143InBlock.gif     * 
144InBlock.gif     * @return a date.
145ExpandedSubBlockEnd.gif     */

146ExpandedSubBlockStart.gifContractedSubBlock.gif    private static Date date(final int day, final int month, final int year) dot.gif{
147InBlock.gif
148InBlock.gif        final Calendar calendar = Calendar.getInstance();
149InBlock.gif        calendar.set(year, month, day);
150InBlock.gif
151InBlock.gif        final Date result = calendar.getTime();
152InBlock.gif        return result;
153InBlock.gif
154ExpandedSubBlockEnd.gif    }

155InBlock.gif
156ExpandedSubBlockStart.gifContractedSubBlock.gif    /** *//**
157InBlock.gif     * 方法名称: 内容摘要:饼图测试
158InBlock.gif     * 
159InBlock.gif     * @return
160InBlock.gif     * @return JFreeChart
161InBlock.gif     * @throws
162ExpandedSubBlockEnd.gif     */

163ExpandedSubBlockStart.gifContractedSubBlock.gif    private JFreeChart createBarChart() dot.gif{
164InBlock.gif        String title = "空调2002年市场占有率";
165InBlock.gif        DefaultPieDataset piedata = new DefaultPieDataset();
166InBlock.gif        piedata.setValue("联想"27.3);
167InBlock.gif    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值