博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ChartDirector与JreeChart这两款web图形报表工具比较
阅读量:2395 次
发布时间:2019-05-10

本文共 5148 字,大约阅读时间需要 17 分钟。

一、引言:

我最近在做项目的时候,要用到图表,其中画图表工具有好多种,今天我们就对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'") 	; 	%> 	 	 	
3D Bar Chart

View Chart Source Code
<%=imageMap1%>

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; %>   
3D Bar Chart

转载地址:http://lpzob.baihongyu.com/

你可能感兴趣的文章
http与https_HTTP与HTTPS
查看>>
node.js运行js_Node.js运行时v8选项列表
查看>>
git教程_出色的Git教程的不完整列表
查看>>
Express,请求参数
查看>>
express发送文件_使用Express发送文件
查看>>
Object toString()方法
查看>>
调试JavaScript的权威指南
查看>>
我如何运行一些JavaScript代码段
查看>>
地理位置api_如何使用地理位置API
查看>>
数据结构设计 数据字典_Go数据结构:字典
查看>>
node_modules文件夹的大小不是问题。 这是一种特权
查看>>
dom 删除所有子元素_如何从DOM元素中删除所有子级
查看>>
html 打印样式控制_如何使用样式打印HTML
查看>>
gatsby_Next.js vs Gatsby vs create-react-app
查看>>
掌握React.Memo
查看>>
golang 延迟_了解Go中的延迟
查看>>
react 组件样式_如何设置React组件的样式
查看>>
node.js 模块_如何创建Node.js模块
查看>>
centos上安装git_如何在CentOS 8上安装Git
查看>>
在JavaScript中优化switch语句
查看>>