在Eclipse RCP中开发JFreeChart示例
来源:互联网 发布:快手李晶淘宝号是多少 编辑:程序博客网 时间:2024/04/29 06:13
有人说,RCP一定会变得非常流行。因为RCP,可以开发界面象Eclipse这样漂亮的桌面程序。那就来做一个JFreeChat的示例吧。
一、下载JFreeChart包
1.http://www.jfree.org/jfreechart/
2.用到的包:(注,我的开发环境是eclipse3.2)
jcommon-1.0.10.jar
jfreechart-1.0.6.jar
jfreechart-1.0.6-experimental.jar
jfreechart-1.0.6-swt.jar
swtgraphics2d.jar
二、新建项目
在Eclipse下如何建立plug-in的内容在Google上一搜一大把,有些人会觉得乏味,但是没关系,这只是一个快速的起步。下面大致说一下。有不明白的,可以参考http://www.vogella.de/articles/RichClientPlatform/article.html#using_jars,非常的详细
1、建完项目后记得把上面提到的JFreeChart包加入的项目“Propertires”的“Java Build Path”中。
2、还需要在项目的META-INF/MANIFEST.MF文件的“runtime”中加入以上的包,不然运行时会说找不相关的类,如下图
三、建立View
建View在上面文档http://www.vogella.de/articles/RichClientPlatform/article.html#using_jars中5.2. Add a view to your application有讲,我在这里大致上几个图说明一下。
1.点击配置文件的“extensions”,选择"org.eclipse.views",右键,》"new"》"view",
2.点击右边class*.;链接,来创建新的类
3.此类的代码如下
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 MyNewView extends ViewPart {
public MyNewView() {
// TODO Auto-generated constructor stub
}
private static PieDataset createDataset() {
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("猪肉", new Double(43.2));
dataset.setValue("牛肉", new Double(10.0));
dataset.setValue("猪肉", new Double(27.5));
dataset.setValue("羊肉", new Double(17.5));
dataset.setValue("鸡肉", new Double(11.0));
dataset.setValue("鸭肉", new Double(19.4));
return dataset;
}
/** *//**
* Creates a chart.
*
* @param dataset
* the dataset.
*
* @return A chart.
*/
private static JFreeChart createChart(PieDataset dataset) {
JFreeChart chart = ChartFactory.createPieChart("肉食品消费统计图示例", // chart
// title
dataset, // data
true, // include legend
true, false);
PiePlot plot = (PiePlot) chart.getPlot();
plot.setSectionOutlinesVisible(false);
plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
plot.setNoDataMessage("没有统计数据");
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,
chart, true);
}
/** *//**
* Passing the focus request to the viewer's control.
*/
public void setFocus() {
}
}
4.修改Perspective类,使程序能够运行
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;
public class Perspective implements IPerspectiveFactory {
public void createInitialLayout(IPageLayout layout) {
layout.addView("jfreechatrcp.MyNewView", IPageLayout.TOP,IPageLayout.RATIO_MAX, IPageLayout.ID_EDITOR_AREA);
}
}
5.运行程序
META-INF/MANIFEST.MF》》Launch as Eclipse application
四、结果
源代码jfreechatRCP.rar,请自行下载jfreechart包
参考文献
http://www.vogella.de/articles/RichClientPlatform/article.html#firstplugin
http://www.vogella.de/articles/EclipseJFreeChart/article.html
- 在Eclipse RCP中开发JFreeChart示例
- 在Eclipse RCP中开发JFreeChart示例
- 在Eclipse RCP中使用JFreeChart报表
- RCP开发---在一个ViewPart中添加JFreechart报表
- 在Eclipse RCP开发中使用jMock
- 在Eclipse RCP开发中利用Trim Areas
- 在eclipse rcp 开发中 动态的显示视图
- 在RCP View中显示JFreeChart报表完成的代码
- 在Eclipse RCP中使用ResourceNavigator
- 在eclipse rcp项目中使用jni
- 介绍接个实用Eclipse RCP开发示例
- 使用Eclipse RCP进行桌面程序开发(四):在Windows中使用Active X控件
- 使用Eclipse RCP进行桌面程序开发(四):在Windows中使用Active X控件
- 使用Eclipse RCP进行桌面程序开发(四):在Windows中使用Active X控件
- 使用Eclipse RCP进行桌面程序开发(四):在Windows中使用Active X控件
- Eclipse RCP开发基础
- Eclipse RCP开发基础
- Eclipse RCP开发常见问题
- 用Eclipse ANT工具生成JFreeChart的所有API文档
- java lang classnotfoundexception com microsoft jdbc sqlserver sqlserverdriver
- CSS常用样式
- JFreeChart概况
- Microsoft .Net Remoting系列专题之三:Remoting事件处理全接触
- 在Eclipse RCP中开发JFreeChart示例
- C++中的内存分配new()
- Microsoft .Net Remoting系列专题之一:.Net Remoting基础篇
- 注册表监控弱点演示程序 v0.2 逆向ASM源码及相关资料
- Microsoft .Net Remoting系列专题之二:Marshal、Disconnect与生命周期以及跟踪服务
- C语言复杂声明的解析
- 人生
- Intel双核与超线程的区别与联系!(转帖)
- .Net中的设计模式—Strategy模式(转载)