jfreechart实现折线图 折线图 颜色代表意义

编程开发子分类百度提供的广告:
当前位置: >
JavaJfreeChart 生成柱状图 扇形图 折线图
JfreeChart 生成柱状图 扇形图 折线图
import java.awt.C
import java.io.F
import java.io.IOE
import org.jfree.chart.ChartF
import org.jfree.chart.ChartU
import org.jfree.chart.JFreeC
import org.jfree.chart.axis.AxisL
import org.jfree.chart.labels.ItemLabelA
import org.jfree.chart.labels.ItemLabelP
import org.jfree.chart.labels.StandardCategoryItemLabelG
import org.jfree.chart.plot.CategoryP
import org.jfree.chart.plot.PlotO
import org.jfree.chart.renderer.category.BarRenderer3D;
import org.jfree.data.category.CategoryD
import org.jfree.data.category.DefaultCategoryD
import org.jfree.data.general.DatasetU
import org.jfree.ui.TextA
&* @author Administrator
public class ZhuZhuang {
&&& &* 最基本的柱状图
&&& public static void tu1(){
&&& &&& DefaultCategoryDataset dataset = new DefaultCategoryDataset();
&&& &&& dataset.addValue(610, &广州&, &猪肉&);
&&& &&& dataset.addValue(220, &广州&, &牛肉&);
&&& &&& dataset.addValue(530, &广州&, &鸡肉&);
&&& &&& dataset.addValue(340, &广州&, &鱼肉&);
&&& &&& JFreeChart chart = ChartFactory.createBarChart3D(&肉类销量统计图&,
&&& &&& &&&&&&&&&&&&&&&&& &肉类&,
&&& &&& &&&&&&&&&&&&&&&&& &销量&,
&&& &&& &&&&&&&&&&&&&&&&& dataset,
&&& &&& &&&&&&&&&&&&&&&&& PlotOrientation.VERTICAL,
&&& &&& &&&&&&&&&&&&&&&&& false,
&&& &&& &&&&&&&&&&&&&&&&& false,
&&& &&& &&&&&&&&&&&&&&&&& false);
&&& &&& try {
&&& &&& &&& ChartUtilities.saveChartAsJPEG(new File(&d:/zhuzhuang-1.jpg&), chart, 700, 500);
&&& &&& } catch (IOException e) {
&&& &&& &&& e.printStackTrace();
&&& &* 3D柱状图
&&& public static void tu2()
&&& &&& double[][] data = new double[][] {{1310}, {720}, {1130}, {440}};
&&& &&& String[] rowKeys = {&猪肉&, &牛肉&,&鸡肉&, &鱼肉&};
&&& &&& String[] columnKeys = {&&};
&&& &&& CategoryDataset dataset = DatasetUtilities.createCategoryDataset(rowKeys, columnKeys, data);
&&& &&& JFreeChart chart = ChartFactory.createBarChart3D(&广州肉类销量统计图&, &肉类&,
&&& &&& &销量&,
&&& &&& dataset,
&&& &&& PlotOrientation.VERTICAL,
&&& &&& true,
&&& &&& false,
&&& &&& false);
&&& &&& try {
&&& &&& &&& ChartUtilities.saveChartAsJPEG(new File(&d:/zhuzhuang-2.jpg&), chart, 700, 500);
&&& &&& } catch (IOException e) {
&&& &&& &&& e.printStackTrace();
&&& &* 3D柱状图-2 带分组
&&& public static void tu3()
&&& &&& double[][] data = new double[][] {{, },
&&& &&& &&&&&&& {720, 700, 680, 640},
&&& &&& &&&&&&& {, 980, 800},
&&& &&& &&&&&&& {440, 400, 360, 300}};
&&& &&& String[] rowKeys = {&猪肉&, &牛肉&,&鸡肉&, &鱼肉&};
&&& &&& String[] columnKeys = {&广州&, &深圳&, &东莞&, &佛山&};
&&& &&& CategoryDataset dataset = DatasetUtilities.createCategoryDataset(rowKeys, columnKeys, data);
&&& &&& JFreeChart chart = ChartFactory.createBarChart3D(&广州肉类销量统计图&, &肉类&,
&&& &&& &销量&,
&&& &&& dataset,
&&& &&& PlotOrientation.VERTICAL,
&&& &&& true,
&&& &&& false,
&&& &&& false);
&&& &&& try {
&&& &&& &&& ChartUtilities.saveChartAsJPEG(new File(&d:/zhuzhuang-3.jpg&), chart, 700, 500);
&&& &&& } catch (IOException e) {
&&& &&& &&& e.printStackTrace();
&&& &* 3D柱状图-3带数值标注
&&& public static void tu4()
&&& &&& double[][] data = new double[][] {{, },
&&& &&& &&& &&& {720, 700, 680, 640},
&&& &&& &&& &&& {, 980, 800},
&&& &&& &&& &&& {440, 400, 360, 300}};
&&& &&& &&& String[] rowKeys = {&猪肉&, &牛肉&,&鸡肉&, &鱼肉&};
&&& &&& &&& String[] columnKeys = {&广州&, &深圳&, &东莞&, &佛山&};
&&& &&& &&& CategoryDataset dataset = DatasetUtilities.createCategoryDataset(rowKeys, columnKeys, data);
&&& &&& &&& JFreeChart chart = ChartFactory.createBarChart3D(&肉类销量统计图&,
&&& &&& &&& &&&&&&&&&&&&&&&&& &肉类&,
&&& &&& &&& &&&&&&&&&&&&&&&&& &销量&,
&&& &&& &&& &&&&&&&&&&&&&&&&& dataset,
&&& &&& &&& &&&&&&&&&&&&&&&&& PlotOrientation.VERTICAL,
&&& &&& &&& &&&&&&&&&&&&&&&&& true,
&&& &&& &&& &&&&&&&&&&&&&&&&& true,
&&& &&& &&& &&&&&&&&&&&&&&&&& false);
&&& &&& &&& CategoryPlot plot = chart.getCategoryPlot();
&&& &&& &&& //设置网格背景颜色
&&& &&& &&& plot.setBackgroundPaint(Color.white);
&&& &&& &&& //设置网格竖线颜色
&&& &&& &&& plot.setDomainGridlinePaint(Color.pink);
&&& &&& &&& //设置网格横线颜色
&&& &&& &&& plot.setRangeGridlinePaint(Color.pink);
&&& &&& &&& //显示每个柱的数值,并修改该数值的字体属性
&&& &&& &&& BarRenderer3D renderer = new BarRenderer3D();
&&& &&& &&& renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
&&& &&& &&& renderer.setBaseItemLabelsVisible(true);
&&& &&& &&& //默认的数字显示在柱子中,通过如下两句可调整数字的显示
&&& &&& &&& //注意:此句很关键,若无此句,那数字的显示会被覆盖,给人数字没有显示出来的问题
&&& &&& &&& renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
&&& &&& &&& renderer.setItemLabelAnchorOffset(10D);
&&& &&& &&& //设置每个地区所包含的平行柱的之间距离
&&& &&& &&& //renderer.setItemMargin(0.3);
&&& &&& &&& plot.setRenderer(renderer);
&&& &&& &&& //设置地区、销量的显示位置
&&& &&& &&& //将下方的&肉类&放到上方
&&& &&& &&& plot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
&&& &&& &&& //将默认放在左边的&销量&放到右方
&&& &&& &&& plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
&&& &&& &&& try {
&&& &&& &&& &&& ChartUtilities.saveChartAsJPEG(new File(&d:/zhuzhuang-4.jpg&), chart, 700, 500);
&&& &&& &&& } catch (IOException e) {
&&& &&& &&& &&& e.printStackTrace();
&&& &&& &&& }
&&& //测试函数
&&& public static void main(String[] args) {
&&& &&& tu1();
&&& &&& tu2();
&&& &&& tu3();
&&& &&& tu4();
import java.awt.C
import java.awt.F
import java.io.F
import java.io.IOE
import org.jfree.chart.ChartF
import org.jfree.chart.ChartU
import org.jfree.chart.JFreeC
import org.jfree.chart.labels.ItemLabelA
import org.jfree.chart.labels.ItemLabelP
import org.jfree.chart.labels.StandardXYItemLabelG
import org.jfree.chart.plot.XYP
import org.jfree.chart.renderer.xy.XYItemR
import org.jfree.chart.renderer.xy.XYLineAndShapeR
import org.jfree.chart.title.TextT
import org.jfree.data.time.M
import org.jfree.data.time.TimeS
import org.jfree.data.time.TimeSeriesC
import org.jfree.ui.RectangleI
import org.jfree.ui.TextA
&* @author Administrator
public class ZheXian {
&&& &* 折线图 1
&&& public static void tu1()
&&& &&& //访问量统计时间线
&&& &&& TimeSeries timeSeries = new TimeSeries(&阿蜜果blog访问量统计&, Month.class);
&&& &&& //时间曲线数据集合
&&& &&& TimeSeriesCollection lineDataset = new TimeSeriesCollection();
&&& &&& //构造数据集合
&&& &&& timeSeries.add(new Month(1, 2007), 11200);
&&& &&& timeSeries.add(new Month(2, 2007), 9000);
&&& &&& timeSeries.add(new Month(3, 2007), 6200);
&&& &&& timeSeries.add(new Month(4, 2007), 8200);
&&& &&& timeSeries.add(new Month(5, 2007), 8200);
&&& &&& timeSeries.add(new Month(6, 2007), 12200);
&&& &&& timeSeries.add(new Month(7, 2007), 13200);
&&& &&& timeSeries.add(new Month(8, 2007), 8300);
&&& &&& timeSeries.add(new Month(9, 2007), 12400);
&&& &&& timeSeries.add(new Month(10, 2007), 12500);
&&& &&& timeSeries.add(new Month(11, 2007), 13600);
&&& &&& timeSeries.add(new Month(12, 2007), 12500);
&&& &&& lineDataset.addSeries(timeSeries);
&&& &&& JFreeChart chart = ChartFactory.createTimeSeriesChart(&访问量统计时间线&, &月份&, &访问量&, lineDataset, true, true, true);
&&& &&& //设置子标题
&&& &&& TextTitle subtitle = new TextTitle(&2007年度&, new Font(&黑体&, Font.BOLD, 12));
&&& &&& chart.addSubtitle(subtitle);
&&& &&& //设置主标题
&&& &&& chart.setTitle(new TextTitle(&阿蜜果blog访问量统计&, new Font(&隶书&, Font.ITALIC, 15)));
&&& &&& chart.setAntiAlias(true);
&&& &&& try {
&&& &&& &&& ChartUtilities.saveChartAsJPEG(new File(&d:/zhexian-1.jpg&), chart, 700, 500);
&&& &&& } catch (IOException e) {
&&& &&& &&& e.printStackTrace();
&&& &* 双折线
&&& public static void tu2()
&&& &&& //访问量统计时间线
&&& &&& TimeSeries timeSeries2006 = new TimeSeries(&2006年度&, Month.class);
&&& &&& TimeSeries timeSeries2007 = new TimeSeries(&2007年度&, Month.class);
&&& &&& //时间曲线数据集合
&&& &&& TimeSeriesCollection lineDataset = new TimeSeriesCollection();
&&& &&& //构造数据集合
&&& &&& timeSeries2006.add(new Month(1, 2007), 7200);
&&& &&& timeSeries2006.add(new Month(2, 2007), 7000);
&&& &&& timeSeries2006.add(new Month(3, 2007), 4200);
&&& &&& timeSeries2006.add(new Month(4, 2007), 8200);
&&& &&& timeSeries2006.add(new Month(5, 2007), 7300);
&&& &&& timeSeries2006.add(new Month(6, 2007), 8200);
&&& &&& timeSeries2006.add(new Month(7, 2007), 9200);
&&& &&& timeSeries2006.add(new Month(8, 2007), 7300);
&&& &&& timeSeries2006.add(new Month(9, 2007), 9400);
&&& &&& timeSeries2006.add(new Month(10, 2007), 7500);
&&& &&& timeSeries2006.add(new Month(11, 2007), 6600);
&&& &&& timeSeries2006.add(new Month(12, 2007), 3500);
&&& &&& timeSeries2007.add(new Month(1, 2007), 10200);
&&& &&& timeSeries2007.add(new Month(2, 2007), 9000);
&&& &&& timeSeries2007.add(new Month(3, 2007), 6200);
&&& &&& timeSeries2007.add(new Month(4, 2007), 8200);
&&& &&& timeSeries2007.add(new Month(5, 2007), 8200);
&&& &&& timeSeries2007.add(new Month(6, 2007), 11200);
&&& &&& timeSeries2007.add(new Month(7, 2007), 13200);
&&& &&& timeSeries2007.add(new Month(8, 2007), 8300);
&&& &&& timeSeries2007.add(new Month(9, 2007), 10400);
&&& &&& timeSeries2007.add(new Month(10, 2007), 12500);
&&& &&& timeSeries2007.add(new Month(11, 2007), 10600);
&&& &&& timeSeries2007.add(new Month(12, 2007), 10500);
&&& &&& lineDataset.addSeries(timeSeries2006);
&&& &&& lineDataset.addSeries(timeSeries2007);
&&& &&& JFreeChart chart = ChartFactory.createTimeSeriesChart(&访问量统计时间线&, &月份&, &访问量&, lineDataset, true, true, true);
&&& &&& //设置子标题
&&& &&& TextTitle subtitle = new TextTitle(&年度访问量对比&, new Font(&黑体&, Font.BOLD, 12));
&&& &&& chart.addSubtitle(subtitle);
&&& &&& //设置主标题
&&& &&& chart.setTitle(new TextTitle(&阿蜜果blog访问量统计&, new Font(&隶书&, Font.ITALIC, 15)));
&&& &&& chart.setAntiAlias(true);
&&& &&& try {
&&& &&& &&& ChartUtilities.saveChartAsJPEG(new File(&d:/zhexian-2.jpg&), chart, 700, 500);
&&& &&& } catch (IOException e) {
&&& &&& &&& e.printStackTrace();
&&& public static void main(String[] arg0s) {
import java.awt.F
import java.io.F
import java.io.IOE
import org.jfree.chart.ChartF
import org.jfree.chart.ChartU
import org.jfree.chart.JFreeC
import org.jfree.chart.plot.PieP
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.data.general.DefaultPieD
import org.jfree.util.R
public class BingTu {
&&& &* 饼图
&&& public static void tu1()
&&& &&& //设置数据集
&&& &&& DefaultPieDataset dataset = new DefaultPieDataset();
&&& &&& dataset.setValue(&初中高级程序员&, 0.55);
&&& &&& dataset.setValue(&项目经理&, 0.1);
&&& &&& dataset.setValue(&系统分析师&, 0.1);
&&& &&& dataset.setValue(&软件架构师&, 0.1);
&&& &&& dataset.setValue(&其他&, 0.2);
&&& &&& //通过工厂类生成JFreeChart对象
&&& &&& JFreeChart chart = ChartFactory.createPieChart3D(&IT行业职业分布图&, dataset, true, false, false);
&&& &&& PiePlot pieplot = (PiePlot) chart.getPlot();
&&& &&& pieplot.setLabelFont(new Font(&宋体&, 0, 12));
&&& &&& //没有数据的时候显示的内容
&&& &&& pieplot.setNoDataMessage(&无数据显示&);
&&& &&& pieplot.setCircular(false);
&&& &&& pieplot.setLabelGap(0.02D);
&&& &&& try {
&&& &&& &&& ChartUtilities.saveChartAsJPEG(new File(&d:/bing-1.jpg&), chart, 700, 500);
&&& &&& } catch (IOException e) {
&&& &&& &&& e.printStackTrace();
&&& &* 饼图 透明度
&&& public static void tu2()
&&& &&& DefaultPieDataset dataset = new DefaultPieDataset();
&&& &&& dataset.setValue(&初中高级程序员&, 0.55);
&&& &&& dataset.setValue(&项目经理&, 0.1);
&&& &&& dataset.setValue(&系统分析师&, 0.1);
&&& &&& dataset.setValue(&软件架构师&, 0.1);
&&& &&& dataset.setValue(&其他&, 0.2);
&&& &&& //通过工厂类生成JFreeChart对象
&&& &&& JFreeChart chart = ChartFactory.createPieChart3D(&IT行业职业分布图&, dataset, true, true, false);
&&& &&& //获得3D的水晶饼图对象
&&& &&& PiePlot3D pieplot3d = (PiePlot3D) chart.getPlot();
&&& &&& //设置开始角度
&&& &&& pieplot3d.setStartAngle(150D);
&&& &&& //设置方向为&顺时针方向&
&&& &&& pieplot3d.setDirection(Rotation.CLOCKWISE);
&&& &&& //设置透明度,0.5F为半透明,1为不透明,0为全透明
&&& &&& pieplot3d.setForegroundAlpha(0.5F);
&&& &&& pieplot3d.setNoDataMessage(&无数据显示&);&&&
&&& &&& try {
&&& &&& &&& ChartUtilities.saveChartAsJPEG(new File(&d:/bing-2.jpg&), chart, 700, 500);
&&& &&& } catch (IOException e) {
&&& &&& &&& e.printStackTrace();
&&& public static void main(String[] args) {| 漏洞检测 |
| 隐藏捆绑 |
jfreechart生成折线图 | 饼图 | 柱状图 | 堆栈柱状图
1.所需包 (1) jfreechart-1.0.8a.jar (2) jcommon-1.0.12.jar 2.运行环境 JDK 1.5以上 3.源码 import java.awt.C import java.awt.F import java.io.F import java.io.FileOutputS import java.text.DecimalF
(1) -1.0.8a.jar
(2) jcommon-1.0.12.jar
2.运行环境
JDK 1.5以上
import java.awt.C
import java.awt.F
import java.io.F
import java.io.FileOutputS
import java.text.DecimalF
import java.text.NumberF
import org.jfree.chart.ChartF
import org.jfree.chart.ChartU
import org.jfree.chart.JFreeC
import org.jfree.chart.axis.CategoryA
import org.jfree.chart.axis.CategoryLabelP
import org.jfree.chart.axis.NumberA
import org.jfree.chart.axis.ValueA
import org.jfree.chart.labels.StandardCategoryItemLabelG
import org.jfree.chart.labels.StandardPieSectionLabelG
import org.jfree.chart.plot.CategoryP
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.chart.plot.PlotO
import org.jfree.chart.renderer.category.BarR
import org.jfree.chart.renderer.category.LineAndShapeR
import org.jfree.chart.renderer.category.StackedBarR
import org.jfree.chart.title.TextT
import org.jfree.data.category.CategoryD
import org.jfree.data.general.DatasetU
import org.jfree.data.general.DefaultPieD
import org.jfree.data.general.PieD
&* 实际取色的时候一定要16位的,这样比较准确
&* @author new
public class TestCreateChart {
&private static final String CHART_PATH = &d:/test/&;
&public static void main(String[] args) {
&&// TODO Auto-generated method stub
&&TestCreateChart pm = new TestCreateChart();
&&// 饼状图
&&pm.makePieChart();
&&// 单组图
&&pm.makeBarChart();
&&// 生成多组图
&&pm.makeBarGroupChart();
&&// 生成堆积柱状图
&&pm.makeStackedBarChart();
&&// 生成折
&&pm.makeLineAndShapeChart();
& * 生成折
&public void makeLineAndShapeChart() {
&&double[][] data = new double[][] { { 672, 766, 223, 540, 126 },
&&&&{ 325, 521, 210, 340, 106 }, { 332, 256, 523, 240, 526 } };
&&String[] rowKeys = { &苹果&, &梨子&, &葡萄& };
&&String[] columnKeys = { &北京&, &上海&, &广州&, &成都&, &深圳& };
&&CategoryDataset dataset = getBarData(data, rowKeys, columnKeys);
&&createTimeXYChar(&折线图&, &x轴&, &y轴&, dataset, &lineAndShap.png&);
& * 生成分组的柱状图
&public void makeBarGroupChart() {
&&double[][] data = new double[][] { { 672, 766, 223, 540, 126 },
&&&&{ 325, 521, 210, 340, 106 }, { 332, 256, 523, 240, 526 } };
&&String[] rowKeys = { &苹果&, &梨子&, &葡萄& };
&&String[] columnKeys = { &北京&, &上海&, &广州&, &成都&, &深圳& };
&&CategoryDataset dataset = getBarData(data, rowKeys, columnKeys);
&&createBarChart(dataset, &x坐标&, &y坐标&, &柱状图&, &barGroup.png&);
& * 生成柱状图
&public void makeBarChart() {
&&double[][] data = new double[][] { { 672, 766, 223, 540, 126 } };
&&String[] rowKeys = { &苹果& };
&&String[] columnKeys = { &北京&, &上海&, &广州&, &成都&, &深圳& };
&&CategoryDataset dataset = getBarData(data, rowKeys, columnKeys);
&&createBarChart(dataset, &x坐标&, &y坐标&, &柱状图&, &bar.png&);
& * 生成柱状图
&public void makeStackedBarChart() {
&&double[][] data = new double[][] { { 0.21, 0.66, 0.23, 0.40, 0.26 },
&&&&{ 0.25, 0.21, 0.10, 0.40, 0.16 } };
&&String[] rowKeys = { &苹果&, &梨子& };
&&String[] columnKeys = { &北京&, &上海&, &广州&, &成都&, &深圳& };
&&CategoryDataset dataset = getBarData(data, rowKeys, columnKeys);
&&createStackedBarChart(dataset, &x坐标&, &y坐标&, &柱状图&, &stsckedBar.png&);
& * 生成饼状图
&public void makePieChart() {
&&double[] data = { 9, 91 };
&&String[] keys = { &失败率&, &成功率& };
&&createValidityComparePimChar(getDataPieSetByUtil(data, keys), &饼状图&,
&&&&&pie2.png&, keys);
(责任编辑:幽灵学院)
------分隔线----------------------------
情景:使用在方法中绑定数据的时候,打开链接,出现400错误。 @RequestMapping(value ...
package com.java.process.import java.awt.Cimport java.awt.Fimport j...
Struts2中访问和添加request、session、application属性 public String execute() {//...
I am going to create today a complete End-to-End SpringMVC 3, Hibernate 3 CRUD t...
【归并排序的思想】 归并排序的思想是如果子数组L和子数组R都是有序的,那么我们可以...
较之c++ 中 public,proctected, private 三种访问控制, java多了默认访问控制。 j...
admin@1744.cc
工作日:9:00-21:00
周 六:9:00-18:00
&&扫一扫关注幽灵学院
广告服务:QQ:jfreechart共有多少种图形?像什么折线图啊,条形图啊之类的,都叫什么名字(英文的)?我现在就7个财富值……少了点_百度作业帮
jfreechart共有多少种图形?像什么折线图啊,条形图啊之类的,都叫什么名字(英文的)?我现在就7个财富值……少了点
jfreechart共有多少种图形?像什么折线图啊,条形图啊之类的,都叫什么名字(英文的)?我现在就7个财富值……少了点
折线图xy,柱状图bar,饼图pie,每种有很多分支,2D,3D,具体你可以参考jfreechart的demojfreechart绘制折线图 - 当那繁华落尽,只剩满地忧伤 - ITeye技术网站
博客分类:
大家共勉啊!~!
public class DrawLineHistogram {
// 图象宽度
// 图象高度
String chartT// 图表标题
S// 副标题
String xT// X轴标题
String yT// Y轴标题
String[]// 图例名称
String category[]; // 统计种类
Double[][]// 绘图数据
String servletURI = "/servlet/DisplayChart";// 映射路径
public DrawLineHistogram() {
this.width = 450;
this.height = 325;
this.chartTitle = "预测数据图";
this.subtitle = "";
this.xTitle = "预测日期";
this.yTitle = "预测数据";
this.cutline = new String[] { "后9月预测数据图" };
this.category = new String[] { "200809", "200810", "200811", "200812", "200901", "200902"
};//日期数组
this.data = new Double[cutline.length][category.length];//数据室double数组
for (int m = 0; m & cutline. m++) {
for (int n = 0; n & category. n++) {
data[m][n] = 1 + Math.random() * 100;
public DrawLineHistogram(int width, int height, String chartTitle,
String subtitle, String xTitle, String yTitle, String[] cutline,
String[] category, Double[][] data) {
this.width =
this.height =
this.chartTitle = chartT
this.subtitle =
this.xTitle = xT
this.yTitle = yT
this.cutline =
this.category =
this.data =
public DrawLineHistogram(int width, int height, String chartTitle,
String subtitle, String xTitle, String yTitle, String[] cutline,
String[] category, Double[][] data, String servletURI) {
this.width =
this.height =
this.chartTitle = chartT
this.subtitle =
this.xTitle = xT
this.yTitle = yT
this.cutline =
this.category =
this.data =
this.servletURI = servletURI;
public String draw(String path) {
// 创建绘图数据集
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for (int m = 0; m & cutline. m++) {
for (int n = 0; n & category. n++) {
dataset.addValue(data[m][n], cutline[m], category[n]);
// 创建图表对象
JFreeChart chart = ChartFactory.createLineChart(chartTitle, // 图表标题
xTitle, // X轴标题
yTitle, // Y轴标题
dataset, // 绘图数据集
PlotOrientation.VERTICAL, // 绘制方向
true, // 显示图例
true, // 采用标准生成器
false // 生成链接
// 自定义图表开始:
if (subtitle.length() & 0) {// 添加副标题
chart.addSubtitle(new TextTitle(subtitle));
GradientPaint chartGP = new GradientPaint(0, 0,
new Color(219, 227, 127), 0, height, Color.WHITE, false);// 创建渐变色对象
chart.setBackgroundPaint(chartGP);// 设置图片背景色
// 通过绘图区对象,可以设置更多的绘图属性
CategoryPlot plot = chart.getCategoryPlot();
plot.setBackgroundPaint(Color.WHITE);// 设置绘图区背景色
plot.setRangeGridlinePaint(Color.RED);// 设置水平方向背景线颜色
plot.setRangeGridlinesVisible(true);// 设置是否显示水平方向背景线,默认值为true
plot.setDomainGridlinePaint(Color.RED);// 设置垂直方向背景线颜色
plot.setDomainGridlinesVisible(true);// 设置是否显示垂直方向背景线,默认值为false
// 获取折线对象
LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot
.getRenderer();
// 定义折线颜色
Color color[] = new Color[cutline.length];
color[0] = Color.GREEN;
for (int i = 0; i & color. i++) {
renderer.setSeriesPaint(i, color[i]);
// 定义折线绘制风格
BasicStroke realLine = new BasicStroke(1.6f);
float dashes[] = { 8.0f };// 定义虚线数组
BasicStroke brokenLine = new BasicStroke(1.6f,// 线条粗细
BasicStroke.CAP_ROUND,// 端点风格
BasicStroke.JOIN_ROUND,// 折点风格
8.f,// 折点处理办法
dashes,// 虚线数组
0.0f);// 虚线偏移量
int special = 0;
for (int i = 0; i & cutline. i++) {
if (i == special) {
renderer.setSeriesStroke(i, realLine);
renderer.setSeriesStroke(i, brokenLine);
// 获得横轴对象
CategoryAxis domainAxis = plot.getDomainAxis();
// 设置横轴绘制属性
domainAxis.setAxisLineStroke(new BasicStroke(1.6f));// 设置轴线粗细
domainAxis.setAxisLinePaint(Color.BLACK);// 设置轴线颜色
domainAxis.setCategoryLabelPositionOffset(5);// 设置统计种类与轴线的颜色
domainAxis.setLabelFont(new Font("黑体", Font.BOLD, 16));// 设置坐标轴标题字体
domainAxis.setLabelPaint(Color.BLACK);// 设置坐标轴标题颜色
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD);// 设置坐标轴标题旋转角度
// 获得纵轴对象
ValueAxis rangeAxis = plot.getRangeAxis();
// 设置纵轴绘制属性
rangeAxis.setAxisLineStroke(new BasicStroke(1.6f));// 设置轴线粗细
rangeAxis.setAxisLinePaint(Color.BLACK);// 设置轴线颜色
//rangeAxis.setUpperBound(100.0f);// 设置坐标最大值
//rangeAxis.setTickMarkStroke(new BasicStroke(1.6f));// 设置坐标标记大小
rangeAxis.setTickMarkPaint(Color.BLACK);// 设置坐标标记颜色
rangeAxis.setLabelFont(new Font("黑体", Font.BOLD, 16));// 设置坐标轴标题字体
rangeAxis.setLabelPaint(Color.BLACK);// 设置坐标轴标题颜色
rangeAxis.setLabelAngle(Math.PI / 2);// 设置坐标轴标题旋转角度
// 自定义图表结束!
// 固定用法
ChartRenderingInfo info = new ChartRenderingInfo(
new StandardEntityCollection());
//解决中文乱码问题
CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
CategoryAxis domainAxis1 = categoryplot.getDomainAxis();
TextTitle textTitle = chart.getTitle();
textTitle.setFont(new Font("黑体", Font.PLAIN, 20));
domainAxis1.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 11));
domainAxis1.setLabelFont(new Font("宋体", Font.PLAIN, 12));
numberaxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 12));
numberaxis.setLabelFont(new Font("黑体", Font.PLAIN, 12));
chart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 12));
//把图片写入指定路径,生成图片
FileOutputStream fos_jpg =
String imagePath = path+"\\fruit4.jpeg";
fos_jpg = new FileOutputStream(path+"\\fruit4.jpeg");
ChartUtilities
.writeChartAsJPEG(fos_jpg,chart,width,height);
} catch (Exception e) {
} finally {
fos_jpg.close();
} catch (Exception e) {
// 返回图片浏览路径
jeasonjack
浏览: 17438 次
来自: 北京
谢谢!最近正好再研究报表作图,虽然朋友推荐我用帆软报表,不过你 ...
&div class=&quote_title ...
版主您好:
想问下程序中flag的作用 拿掉可以么谢谢额
好像日期是星期日,会出错的
Try XML library Simple or XStre ...

我要回帖

更多关于 jfreechart画折线图 的文章

 

随机推荐