JFreeChart应用实例-折线图
http://www.tuicool.com/articles/Nr2Yna
JFreeChart在制作折线图的时候可以使用两种不同的方式
package Line; import java.awt.Color;
import java.awt.Font;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.StandardChartTheme;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset; public class Line {
public static void main(String[] args) {
StandardChartTheme mChartTheme = new StandardChartTheme("CN");
mChartTheme.setLargeFont(new Font("黑体", Font.BOLD, 20));
mChartTheme.setExtraLargeFont(new Font("宋体", Font.PLAIN, 15));
mChartTheme.setRegularFont(new Font("宋体", Font.PLAIN, 15));
ChartFactory.setChartTheme(mChartTheme);
CategoryDataset mDataset = GetDataset();
JFreeChart mChart = ChartFactory.createLineChart(
"折线图",
"年份",
"数量",
mDataset,
PlotOrientation.VERTICAL,
true,
true,
false); CategoryPlot mPlot = (CategoryPlot)mChart.getPlot();
mPlot.setBackgroundPaint(Color.LIGHT_GRAY);
mPlot.setRangeGridlinePaint(Color.BLUE);//背景底部横虚线
mPlot.setOutlinePaint(Color.RED);//边界线 ChartFrame mChartFrame = new ChartFrame("折线图", mChart);
mChartFrame.pack();
mChartFrame.setVisible(true); }
public static CategoryDataset GetDataset()
{
DefaultCategoryDataset mDataset = new DefaultCategoryDataset();
mDataset.addValue(1, "First", "2013");
mDataset.addValue(3, "First", "2014");
mDataset.addValue(2, "First", "2015");
mDataset.addValue(6, "First", "2016");
mDataset.addValue(5, "First", "2017");
mDataset.addValue(12, "First", "2018");
mDataset.addValue(14, "Second", "2013");
mDataset.addValue(13, "Second", "2014");
mDataset.addValue(12, "Second", "2015");
mDataset.addValue(9, "Second", "2016");
mDataset.addValue(5, "Second", "2017");
mDataset.addValue(7, "Second", "2018");
return mDataset;
} }
第二种方式:
package Line; import java.awt.Font; import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.StandardChartTheme;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection; public class XYLine {
public static void main(String[] args) {
StandardChartTheme mChartTheme = new StandardChartTheme("CN");
mChartTheme.setLargeFont(new Font("黑体", Font.BOLD, 20));
mChartTheme.setExtraLargeFont(new Font("宋体", Font.PLAIN, 15));
mChartTheme.setRegularFont(new Font("宋体", Font.PLAIN, 15));
ChartFactory.setChartTheme(mChartTheme);
XYSeriesCollection mCollection = GetCollection();
JFreeChart mChart = ChartFactory.createXYLineChart(
"折线图",
"X",
"Y",
mCollection,
PlotOrientation.VERTICAL,
true,
true,
false);
ChartFrame mChartFrame = new ChartFrame("折线图", mChart);
mChartFrame.pack();
mChartFrame.setVisible(true); }
public static XYSeriesCollection GetCollection()
{
XYSeriesCollection mCollection = new XYSeriesCollection();
XYSeries mSeriesFirst = new XYSeries("First");
mSeriesFirst.add(1.0D, 1.0D);
mSeriesFirst.add(2D, 4D);
mSeriesFirst.add(3D, 3D);
mSeriesFirst.add(4D, 5D);
mSeriesFirst.add(5D, 5D);
mSeriesFirst.add(6D, 7D);
mSeriesFirst.add(7D, 7D);
mSeriesFirst.add(8D, 8D);
XYSeries mSeriesSecond = new XYSeries("Second");
mSeriesSecond.add(1.0D, 5D);
mSeriesSecond.add(2D, 7D);
mSeriesSecond.add(3D, 6D);
mSeriesSecond.add(4D, 8D);
mSeriesSecond.add(5D, 4D);
mSeriesSecond.add(6D, 4D);
mSeriesSecond.add(7D, 2D);
mSeriesSecond.add(8D, 1.0D);
mCollection.addSeries(mSeriesFirst);
mCollection.addSeries(mSeriesSecond);
return mCollection;
} }
JFreeChart应用实例-折线图的更多相关文章
- struts2整合JFreechart 饼图、折线图、柱形图
struts2整合JFreechart 饼图.折线图.柱形图 上效果图: 当然可以将数据导出图片格式存储.具体下的链接里的文件有保存成图片的操作. 因为是strust2整合JFreechart,所以s ...
- JFreeChart在制作折线图
JFreeChart在制作折线图的时候可以使用两种不同的方式 package Line; import java.awt.Color; import java.awt.Font; import org ...
- JFreeChart绘制XY折线图(工具类设计)
准备用Java写通信的仿真平台作为毕业设计,相比matlab绘图,Java绘图需要自己去写很多工具类,博主在这采用了JFreeChart的开源解决方案,摸索着自己写了一个XY折线图工具类,话不多说贴源 ...
- JFreeChart 之折线图
JFreeChart 之折线图 一.JFreeChart 简介 JFreeChart是JAVA平台上的一个开放的图表绘制类库.它完全使用JAVA语言编写,是为applications, applets ...
- JFreeChart绘制折线图实例
JFreeChart是JAVA平台上的一个开放的第三方图表绘制类库.只要下载JFreeChart的类库,导入项目即可使用.下面是一个绘制折线图的实例.各处注释都已经写的比较清晰了. package c ...
- JFreeChart 图表生成实例(饼图、柱状图、折线图、时序图)
import java.awt.BasicStroke; import java.awt.Color; import java.io.FileOutputStream; import java.io. ...
- java利用JFreeChart实现各种数据统计图(柱形图,饼图,折线图)
最近在做数据挖掘的课程设计,需要将数据分析的结果很直观的展现给用户,这就要用到数据统计图,要实现这个功能就需要几个第三方包了: 1. jfreechart-1.0.13.jar 2. ...
- 利用JFreeChart生成折线图 (4) (转自 JSP开发技术大全)
利用JFreeChart生成折线图 (4) (转自 JSP开发技术大全) 14.4 利用JFreeChart生成折线图 通过JFreeChart插件,既可以生成普通效果的折线图,也可以生成3D效果的折 ...
- 使用jfreechart生成柱状图、折线图、和饼状图
JFreeChart是JAVA平台上的一个开放的图表绘制类库.它完全使用JAVA语言编写,是为applications, applets, servlets 以及JSP等使用所设计.下面我就详细介绍如 ...
随机推荐
- UVa 12563 劲歌金曲 刘汝佳第二版例题9-5;
Problem J Jin Ge Jin Qu [h]ao (If you smiled when you see the title, this problem is for you ^_^) Fo ...
- grails 解决emoji标签存入mysql
domain将存储emoji属性类型设置位byte[] class UserTest { byte[] nameBytes //存储emoji表情字段 Date dateCreated //grail ...
- 如何使用 TP中的公共函数 (定义在common/common.php中的函数)
如何使用 TP中的公共函数 (定义在common/common.php中的函数) (2011-09-30 15:32:09) 转载▼ 标签: 杂谈 1.在common/common.php 中有个 ...
- Matlab字符串分割
data = '1.21, 1.985, 1.955, 2.015, 1.885'; C = strsplit(data,', ') C = '1.21' '1.985' '1.955' '2.015 ...
- 任何应用程序都可拥有 Web Service 组件。
任何应用程序都可拥有 Web Service 组件. Web Service 的创建与编程语言的种类无关. 本章节我们将为大家介绍使用 PHP 的 SOAP 扩展来创建 Web Service. SO ...
- Web Services 平台元素
Web Services 拥有三种基本的元素:SOAP.WSDL 以及 UDDI. 什么是 SOAP? 基本的 Web services 平台是 XML + HTTP. SOAP 指简易对象访问协议 ...
- Servlet 国际化
在我们开始之前,先来看看三个重要术语: 国际化(i18n):这意味着一个网站提供了不同版本的翻译成访问者的语言或国籍的内容. 本地化(l10n):这意味着向网站添加资源,以使其适应特定的地理或文化区域 ...
- 移动web开发经验总结(转)
1.<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, minimum-sca ...
- day9笔记--文件操作
文件操作 计算机系统分为:计算机硬件,操作系统,应用程序三部分. 我们用python或其他语言编写的应用程序若想要把数据永久保存下来,必须要保存于硬盘中,这就涉及到应用程序要操作硬件,众所周知,应用 ...
- 记录-java执行请求的URL
package wzh.Http; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStr ...