您的位置:首页 > 其它

ChartDirector与JreeChart这两款web图形报表工具比较

2011-12-05 11:47 330 查看


一、引言:

我最近在做项目的时候,要用到图表,其中画图表工具有好多种,今天我们就对ChartDirector与JreeChart这2种学习和比较,掌握技术路径,即掌握安装配置方式,接口,调用方法,例子等。

1.1 、下载了ChartDirector,挺简单的,照着提供的jsp的例子,改一下数据、横坐标内容就马上能运行了,提供的函数命名也很规范,一看大概就知道用途,挺好理解的,生成的图表也很漂亮。

1.2 、下载JreeChart,这个东西配置也挺简单的,图表质量不如ChartDirector好看,而且生成的图片的大小还大。


二、ChartDirector与JreeChart的介绍与比较

2.1、官方网址

ChartDirector: http://www.advsofteng.com/
JreeChart: http://www.jfree.org/jfreechart/index.html
2.2、基本介绍

两款都是流行的web图表工具:


ChartDirector:

ChartDirector is a fast and powerful charting component for creating professional and clickable charts. It's innovative ChartDirector Mark Up Language, flexible object oriented API, layering architecture and advanced coloring system provide unprecedent chart
design, formatting and customization capabilities to developers. Supports numerous chart types - Pie, donut, bar, line, spline, step line, trend line, curve-fitting, inter-line coloring, area, scatter, bubble, floating box, box-whisker, waterfall, finance
(numerous indicators support), gantt, vector, radar, polar, rose, angular and linear meters and guages. ChartDirector is 100% pure Java code and is suitable for both client and server side usage. Specially designed graphics subsystem allows ChartDirector to
run on headless servers without requiring headless support. Includes SWING controls to support client side applications. Easy to use and with comprehensive documentation. Come with numerous examples.


JreeChart:

JFreeChart是一个开源的 JAVA 项目,它主要用来开发各种各样的图表,这些图表包括:饼图、柱状图 ( 普通柱状图以及堆栈柱状图 ) 、线图、区域图、分布图、混合图、甘特图以及一些仪表盘等等。在这些不同式样的图表上可以满足目前商业系统的要求。 JFreeChart 是一种基于 JAVA 语言的图表开发技术。 JFreeChart 可用于 Servlet 、 JSP 、 Applet 、 Java Appication 环境中,通过 JDBC 可动态显示任何数据库数据,结合 Itext 可以输出至 PDF
文件。

2.3、收费情况

ChartDirector: 商业;价格根据使用权限不同在59美元到749美元之间;也可以免费使用,只是在画出来的图形下面都有一条它的广告条。网上有破解方法,破解后图形下面不再出现它的广告条。

JreeChart: 开源;但是文档要花钱买,40美元;

2.4、支持语言

ChartDirector: 支持很多种语言,例如.NET, Java, ASP, COM,VB, PHP, Perl, Python,Ruby, ColdFusion, C++等;

JreeChart: Java;

2.5、图表比较

ChartDirector: 图表特别精细,漂亮;
样例库:http://www.advsofteng.com/gallery.html

JreeChart: 画出来的图形不够精细,看起来有些模糊;图表的文字边缘、颜色和颜色的分界也比较模糊。
样例库:http://www.jfree.org/jfreechart/samples.html

2.6、对中文问题支持的比较

ChartDirector: 中文的问题,比较容易解决。

JreeChart: 虽然有字体的解决办法,但仍然存在问题。他使用的默认字体显示出来的中文会很模糊,你可能需要修改源代码。

2.7、开发使用易用性比较

从自己分别使用它们用jsp显示柱状图的例子来看,两者的开发的易用性差不多,都是设置一下数据、横坐标等就可以了。


三、分别用ChartDirector和JFreeChart画柱状图的JSP程序示例

3.1、用ChartDirector在JSP中画统计图

下面是一个柱状图的例子:

范例程序:
<%@page import="ChartDirector.*" %>
<%
//The data for the bar chart
double[] data = {85, 156, 179.5, 211, 123};
//The labels for the bar chart
String[] labels = {"Mon", "Tue",
"Wed", "Thu", "Fri"};
//Create a XYChart object of size 300 x 280 pixels
XYChart c = new XYChart(300, 280);
//Set the plotarea at (45, 30) and of size 200 x 200 pixels
c.setPlotArea(45, 30, 200, 200);
//Add a title to the chart
c.addTitle("Weekly Server Load");
//Add a title to the y axis
c.yAxis().setTitle("MBytes");
//Add a title to the x axis
c.xAxis().setTitle("Work Week 25");
//Add a bar chart layer with green (0x00ff00)
bars using the given data
c.addBarLayer(data, 0xff00).set3D();
//Set the labels on the x axis.
c.xAxis().setLabels(labels);
//output the chart
String chart1URL = c.makeSession(request, "chart1");
//include tool tip for the chart
String imageMap1 = c.getHTMLImageMap("", "",
"title='{xLabel}: {value} MBytes'")
;
%>
<html>
<body topmargin="5" leftmargin="5"
rightmargin="0">
<div style="font-size:18pt; font-family:verdana;
font-weight:bold">
3D Bar Chart
</div>
<hr color="#000080">
<a href="viewsource.jsp?file=<%=request.
getServletPath()%>">
<font size="2" face="Verdana"
>View Chart Source Code</font>
</a>
</div>
<br>
<img src='<%=response.encodeURL("getchart.jsp?"+chart1URL)%>'
usemap="#map1" border="0">
<map name="map1"><%=imageMap1%></map>
</body>
</html>

3.2、用JFreeChart画柱状图的范例

这个范例说明如何用JFreeChart画简单的柱状图,下面是一个JSP的简单范例:
<%@ page contentType="text/html; charset=GB2312" %>
<%@ page import="java.awt.*, java.text.*, java.util.*" %>
<%@ page import="org.jfree.chart.*" %>
<%@ page import="org.jfree.chart.axis.*" %>
<%@ page import="org.jfree.chart.labels.
StandardCategoryItemLabelGenerator" %>
<%@ page import="org.jfree.chart.plot.*" %>
<%@ page import="org.jfree.chart.renderer.*" %>
<%@ page import="org.jfree.chart.servlet.ServletUtilities" %>
<%@ page import="org.jfree.data.DefaultCategoryDataset" %>
<%@ page import="org.jfree.ui.TextAnchor" %>
<%
//The data for the bar chart
double[] data = {85, 156, 179.5, 211, 123};
//The labels for the bar chart
String[] labels = {"Mon", "Tue",
"Wed", "Thu", "Fri"};
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for (int i = 0; i < data.length; i++) {
dataset.addValue(data[i], null, labels[i]);
}
JFreeChart chart = ChartFactory.createBarChart3D(
"Weekly Server Load", "Work Week 25",
"MBytes", dataset,
PlotOrientation.VERTICAL, false, false, false);
chart.setBackgroundPaint(new Color(0xE1E1E1));
CategoryPlot plot = chart.getCategoryPlot();
// 设置Y轴显示整数
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
CategoryAxis domainAxis = plot.getDomainAxis();
//设置距离图片左端距离
domainAxis.setLowerMargin(0.05);
BarRenderer3D renderer = new BarRenderer3D();
//设置柱的颜色
renderer.setSeriesPaint(0, new Color(0xff00));
plot.setRenderer(renderer);
String filename = ServletUtilities.saveChartAsPNG(
chart, 300, 280, null, session);
String graphURL = request.getContextPath() +
"/displayChart?filename=" + filename;
%>
<html>
<body topmargin="5"
leftmargin="5" rightmargin="0">
<div style="font-size:18pt;
font-family:verdana; font-weight:bold">
3D Bar Chart
</div>
<br>
<img src="<%= graphURL %>" border=0>
</body>
</html>

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: