- 浏览: 271026 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
tonytony3:
THANK YOU
Android多级树形菜单的实现 -
haiyang08101:
deleteNumber = "421f481e-7 ...
java对xml文件做增删改查 -
求求你帮帮我:
怎么把我的空格也当成节点处理了?
java对xml文件做增删改查 -
求求你帮帮我:
deleteNumber = "421f481e-7 ...
java对xml文件做增删改查 -
lpj13579:
多谢分享,学习学习
高仿小米盒子UI效果实现
三维的柱状图
多行的柱状图
前期准备工作,以及页面调用可以参考JFreeChart开发--饼状 图(1)
这里只有参考图和后台代码
对应代码
一般的柱状图
package chart;
import java.awt.Color;
import java.awt.Font;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpSession;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
public class Barchart2D {
private static CategoryDataset createDataset() {
String s = "生源省份";//这个就是用于说明图形颜色表的的是什么意思
String s1 = "北京";
String s2 = "天津";
String s3 = "河北";
String s4 = "安徽";
String s5 = "辽宁";
String s6 = "河南";
String s7 = "山东";
DefaultCategoryDataset defaultCategoryDataset = new DefaultCategoryDataset();
defaultCategoryDataset.addValue(2000, s, s1);
defaultCategoryDataset.addValue(600, s, s2);
defaultCategoryDataset.addValue(1200, s, s3);
defaultCategoryDataset.addValue(579, s, s4);
defaultCategoryDataset.addValue(347, s, s5);
defaultCategoryDataset.addValue(468, s, s6);
defaultCategoryDataset.addValue(2000, s, s7);
return defaultCategoryDataset;
}
private static JFreeChart createChart(CategoryDataset categorydataset) {
String name = "学校生源统计柱状图";
String x_name = "省份";
String y_name = "数量";
System.out.println("name=" + name);
System.out.println("x_name=" + x_name);
JFreeChart jfreechart = ChartFactory.createBarChart(name, x_name,
y_name, categorydataset, PlotOrientation.VERTICAL, true, true,
false);
jfreechart.setBackgroundPaint(Color.white);//Color 是paint类型的对象
CategoryPlot categoryplot = jfreechart.getCategoryPlot();
NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
CategoryAxis domainAxis = categoryplot.getDomainAxis();
//定义字体格式
Font font = new Font("微软雅黑", Font.CENTER_BASELINE, 12);
TextTitle title = new TextTitle("Liguokun 李国坤2D图");
//设置标题的格式
title.setFont(font);
//把标题设置到图片里面
jfreechart.setTitle(title);
domainAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 11));
domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12));
numberaxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 12));
numberaxis.setLabelFont(new Font("黑体", Font.PLAIN, 12));
jfreechart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 12));
categoryplot.setDomainGridlinePaint(Color.white);
categoryplot.setDomainGridlinesVisible(true);
categoryplot.setDomainGridlinePaint(Color.blue);
//下面用来让柱图更加好看
BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
barrenderer.setDrawBarOutline(true);
barrenderer.setOutlinePaint(Color.black);//加了个黑边,
barrenderer.setMaximumBarWidth(0.05);
barrenderer.setSeriesFillPaint(0, Color.blue);
return jfreechart;
}
public static String generateBarChart(HttpSession session, PrintWriter pw) {
String filename = "";
CategoryDataset categorydataset = createDataset();//在类里可以调用私有的成员啊
JFreeChart jfreechart = createChart(categorydataset);
ChartRenderingInfo info = new ChartRenderingInfo(
new StandardEntityCollection());
try {
filename = ServletUtilities.saveChartAsPNG(jfreechart, 500, 300,
info, session);
} catch (IOException e) {
e.printStackTrace();
}
try {
ChartUtilities.writeImageMap(pw, filename, info, false);
} catch (IOException e) {
e.printStackTrace();
}
pw.flush();
return filename;
}
}
三维的柱状图
package chart;
import java.awt.Color;
import java.awt.Font;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpSession;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
public class Barchart3D {
private static CategoryDataset createDataset() {
String s = "生源省份";//这个就是用于说明图形颜色表的的是什么意思
String s1 = "北京";
String s2 = "天津";
String s3 = "河北";
String s4 = "安徽";
String s5 = "辽宁";
String s6 = "河南";
String s7 = "山东";
DefaultCategoryDataset defaultCategoryDataset = new DefaultCategoryDataset();
defaultCategoryDataset.addValue(2000, s, s1);
defaultCategoryDataset.addValue(600, s, s2);
defaultCategoryDataset.addValue(1200, s, s3);
defaultCategoryDataset.addValue(579, s, s4);
defaultCategoryDataset.addValue(347, s, s5);
defaultCategoryDataset.addValue(468, s, s6);
defaultCategoryDataset.addValue(2000, s, s7);
return defaultCategoryDataset;
}
private static JFreeChart createChart(CategoryDataset categorydataset) {
String name = "学校生源统计柱状图";
String x_name = "省份";
String y_name = "数量";
System.out.println("name=" + name);
System.out.println("x_name=" + x_name);
//createBarChart3D()只要把这个函数改为3D就可以实现三维效果了,这是与2D惟一的不同之处
JFreeChart jfreechart = ChartFactory.createBarChart3D(name, x_name,
y_name, categorydataset, PlotOrientation.VERTICAL, true, true,
false);
jfreechart.setBackgroundPaint(Color.white);//Color 是paint类型的对象
CategoryPlot categoryplot = jfreechart.getCategoryPlot();
NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
CategoryAxis domainAxis = categoryplot.getDomainAxis();
//定义字体格式
Font font = new Font("微软雅黑", Font.CENTER_BASELINE, 12);
TextTitle title = new TextTitle("Liguokun 李国坤3D图");
//设置标题的格式
title.setFont(font);
//把标题设置到图片里面
jfreechart.setTitle(title);
domainAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 11));
domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12));
numberaxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 12));
numberaxis.setLabelFont(new Font("黑体", Font.PLAIN, 12));
jfreechart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 12));
categoryplot.setDomainGridlinePaint(Color.white);
categoryplot.setDomainGridlinesVisible(true);
categoryplot.setDomainGridlinePaint(Color.BLUE);
// 下面用来让柱图更加好看
BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
barrenderer.setDrawBarOutline(true);
barrenderer.setOutlinePaint(Color.black);//加了个黑边,
barrenderer.setMaximumBarWidth(0.05);
barrenderer.setSeriesFillPaint(0, Color.blue);
return jfreechart;
}
public static String generateBarChart(HttpSession session, PrintWriter pw) {
String filename = "";
CategoryDataset categorydataset = createDataset();//在类里可以调用私有的成员啊
JFreeChart jfreechart = createChart(categorydataset);
ChartRenderingInfo info = new ChartRenderingInfo(
new StandardEntityCollection());
try {
filename = ServletUtilities.saveChartAsPNG(jfreechart, 500, 300,
info, session);
} catch (IOException e) {
e.printStackTrace();
}
try {
ChartUtilities.writeImageMap(pw, filename, info, false);
} catch (IOException e) {
e.printStackTrace();
}
pw.flush();
return filename;
}
}
竖的柱状图
package chart;
import java.awt.Color;
import java.awt.Font;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpSession;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
public class Barchart2DHorizontal {
private static CategoryDataset createDataset() {
String s = "生源省份";//这个就是用于说明图形颜色表的的是什么意思
String s1 = "北京";
String s2 = "天津";
String s3 = "河北";
String s4 = "安徽";
String s5 = "辽宁";
String s6 = "河南";
String s7 = "山东";
DefaultCategoryDataset defaultCategoryDataset = new DefaultCategoryDataset();
defaultCategoryDataset.addValue(2000, s, s1);
defaultCategoryDataset.addValue(600, s, s2);
defaultCategoryDataset.addValue(1200, s, s3);
defaultCategoryDataset.addValue(579, s, s4);
defaultCategoryDataset.addValue(347, s, s5);
defaultCategoryDataset.addValue(468, s, s6);
defaultCategoryDataset.addValue(2000, s, s7);
return defaultCategoryDataset;
}
private static JFreeChart createChart(CategoryDataset categorydataset) {
String name = "学校生源统计柱状图";
String x_name = "省份";
String y_name = "数量";
System.out.println("name=" + name);
System.out.println("x_name=" + x_name);
//竖的变横七竖八的,只要改一个地方PlotOrientation.HORIZONTAL,PlotOrientation.VERTICAL
JFreeChart jfreechart = ChartFactory.createBarChart(name, x_name,
y_name, categorydataset, PlotOrientation.HORIZONTAL, true,
true, false);
jfreechart.setBackgroundPaint(Color.white);//Color 是paint类型的对象
CategoryPlot categoryplot = jfreechart.getCategoryPlot();
NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
CategoryAxis domainAxis = categoryplot.getDomainAxis();
//定义字体格式
Font font = new Font("微软雅黑", Font.CENTER_BASELINE, 12);
TextTitle title = new TextTitle("Liguokun 李国坤2D横向图");
//设置标题的格式
title.setFont(font);
//把标题设置到图片里面
jfreechart.setTitle(title);
domainAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 11));
domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12));
numberaxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 12));
numberaxis.setLabelFont(new Font("黑体", Font.PLAIN, 12));
jfreechart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 12));
categoryplot.setDomainGridlinePaint(Color.white);
categoryplot.setDomainGridlinesVisible(true);
categoryplot.setDomainGridlinePaint(Color.BLUE);
return jfreechart;
}
public static String generateBarChart(HttpSession session, PrintWriter pw) {
String filename = "";
CategoryDataset categorydataset = createDataset();//在类里可以调用私有的成员啊
JFreeChart jfreechart = createChart(categorydataset);
ChartRenderingInfo info = new ChartRenderingInfo(
new StandardEntityCollection());
try {
filename = ServletUtilities.saveChartAsPNG(jfreechart, 500, 300,
info, session);
} catch (IOException e) {
e.printStackTrace();
}
try {
ChartUtilities.writeImageMap(pw, filename, info, false);
} catch (IOException e) {
e.printStackTrace();
}
pw.flush();
return filename;
}
}
多行的柱状图
package chart;
import java.awt.Color;
import java.awt.Font;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpSession;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
public class MutiBarchart2D {
private static CategoryDataset createDataset() {
String boy = "男生人数";//这个就是用于说明图形颜色表的的是什么意思
String girl = "女生人数";
String s1 = "北京";
String s2 = "天津";
String s3 = "河北";
String s4 = "安徽";
String s5 = "辽宁";
String s6 = "河南";
String s7 = "山东";
DefaultCategoryDataset defaultCategoryDataset = new DefaultCategoryDataset();
defaultCategoryDataset.addValue(2000, boy, s1);
defaultCategoryDataset.addValue(600, boy, s2);
defaultCategoryDataset.addValue(1200, boy, s3);
defaultCategoryDataset.addValue(579, boy, s4);
defaultCategoryDataset.addValue(347, boy, s5);
defaultCategoryDataset.addValue(468, boy, s6);
defaultCategoryDataset.addValue(2000, boy, s7);
defaultCategoryDataset.addValue(1300, girl, s1);
defaultCategoryDataset.addValue(607, girl, s2);
defaultCategoryDataset.addValue(1660, girl, s3);
defaultCategoryDataset.addValue(589, girl, s4);
defaultCategoryDataset.addValue(247, girl, s5);
defaultCategoryDataset.addValue(668, girl, s6);
defaultCategoryDataset.addValue(290, girl, s7);
return defaultCategoryDataset;
}
private static JFreeChart createChart(CategoryDataset categorydataset) {
String name = "学校生源统计柱状图";
String x_name = "省份";
String y_name = "数量";
System.out.println("name=" + name);
System.out.println("x_name=" + x_name);
JFreeChart jfreechart = ChartFactory.createBarChart(name, x_name,
y_name, categorydataset, PlotOrientation.VERTICAL, true, true,
false);
jfreechart.setBackgroundPaint(Color.white);//Color 是paint类型的对象
CategoryPlot categoryplot = jfreechart.getCategoryPlot();
NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
CategoryAxis domainAxis = categoryplot.getDomainAxis();
//定义字体格式
Font font = new Font("微软雅黑", Font.CENTER_BASELINE, 12);
TextTitle title = new TextTitle("Liguokun 李国坤多维2D图");
//设置标题的格式
title.setFont(font);
//把标题设置到图片里面
jfreechart.setTitle(title);
domainAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 11));
domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12));
numberaxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 12));
numberaxis.setLabelFont(new Font("黑体", Font.PLAIN, 12));
jfreechart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 12));
categoryplot.setDomainGridlinePaint(Color.white);
categoryplot.setDomainGridlinesVisible(true);
categoryplot.setDomainGridlinePaint(Color.blue);
//下面用来让柱图更加好看
BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
barrenderer.setDrawBarOutline(true);
barrenderer.setOutlinePaint(Color.black);//加了个黑边,
barrenderer.setMaximumBarWidth(0.05);
barrenderer.setSeriesFillPaint(0, Color.blue);
return jfreechart;
}
public static String generateBarChart(HttpSession session, PrintWriter pw) {
String filename = "";
CategoryDataset categorydataset = createDataset();//在类里可以调用私有的成员啊
JFreeChart jfreechart = createChart(categorydataset);
ChartRenderingInfo info = new ChartRenderingInfo(
new StandardEntityCollection());
try {
filename = ServletUtilities.saveChartAsPNG(jfreechart, 500, 300,
info, session);
} catch (IOException e) {
e.printStackTrace();
}
try {
ChartUtilities.writeImageMap(pw, filename, info, false);
} catch (IOException e) {
e.printStackTrace();
}
pw.flush();
return filename;
}
}
前期准备工作,以及页面调用可以参考JFreeChart开发--饼状 图(1)
这里只有参考图和后台代码
对应代码
一般的柱状图
package chart;
import java.awt.Color;
import java.awt.Font;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpSession;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
public class Barchart2D {
private static CategoryDataset createDataset() {
String s = "生源省份";//这个就是用于说明图形颜色表的的是什么意思
String s1 = "北京";
String s2 = "天津";
String s3 = "河北";
String s4 = "安徽";
String s5 = "辽宁";
String s6 = "河南";
String s7 = "山东";
DefaultCategoryDataset defaultCategoryDataset = new DefaultCategoryDataset();
defaultCategoryDataset.addValue(2000, s, s1);
defaultCategoryDataset.addValue(600, s, s2);
defaultCategoryDataset.addValue(1200, s, s3);
defaultCategoryDataset.addValue(579, s, s4);
defaultCategoryDataset.addValue(347, s, s5);
defaultCategoryDataset.addValue(468, s, s6);
defaultCategoryDataset.addValue(2000, s, s7);
return defaultCategoryDataset;
}
private static JFreeChart createChart(CategoryDataset categorydataset) {
String name = "学校生源统计柱状图";
String x_name = "省份";
String y_name = "数量";
System.out.println("name=" + name);
System.out.println("x_name=" + x_name);
JFreeChart jfreechart = ChartFactory.createBarChart(name, x_name,
y_name, categorydataset, PlotOrientation.VERTICAL, true, true,
false);
jfreechart.setBackgroundPaint(Color.white);//Color 是paint类型的对象
CategoryPlot categoryplot = jfreechart.getCategoryPlot();
NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
CategoryAxis domainAxis = categoryplot.getDomainAxis();
//定义字体格式
Font font = new Font("微软雅黑", Font.CENTER_BASELINE, 12);
TextTitle title = new TextTitle("Liguokun 李国坤2D图");
//设置标题的格式
title.setFont(font);
//把标题设置到图片里面
jfreechart.setTitle(title);
domainAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 11));
domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12));
numberaxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 12));
numberaxis.setLabelFont(new Font("黑体", Font.PLAIN, 12));
jfreechart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 12));
categoryplot.setDomainGridlinePaint(Color.white);
categoryplot.setDomainGridlinesVisible(true);
categoryplot.setDomainGridlinePaint(Color.blue);
//下面用来让柱图更加好看
BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
barrenderer.setDrawBarOutline(true);
barrenderer.setOutlinePaint(Color.black);//加了个黑边,
barrenderer.setMaximumBarWidth(0.05);
barrenderer.setSeriesFillPaint(0, Color.blue);
return jfreechart;
}
public static String generateBarChart(HttpSession session, PrintWriter pw) {
String filename = "";
CategoryDataset categorydataset = createDataset();//在类里可以调用私有的成员啊
JFreeChart jfreechart = createChart(categorydataset);
ChartRenderingInfo info = new ChartRenderingInfo(
new StandardEntityCollection());
try {
filename = ServletUtilities.saveChartAsPNG(jfreechart, 500, 300,
info, session);
} catch (IOException e) {
e.printStackTrace();
}
try {
ChartUtilities.writeImageMap(pw, filename, info, false);
} catch (IOException e) {
e.printStackTrace();
}
pw.flush();
return filename;
}
}
三维的柱状图
package chart;
import java.awt.Color;
import java.awt.Font;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpSession;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
public class Barchart3D {
private static CategoryDataset createDataset() {
String s = "生源省份";//这个就是用于说明图形颜色表的的是什么意思
String s1 = "北京";
String s2 = "天津";
String s3 = "河北";
String s4 = "安徽";
String s5 = "辽宁";
String s6 = "河南";
String s7 = "山东";
DefaultCategoryDataset defaultCategoryDataset = new DefaultCategoryDataset();
defaultCategoryDataset.addValue(2000, s, s1);
defaultCategoryDataset.addValue(600, s, s2);
defaultCategoryDataset.addValue(1200, s, s3);
defaultCategoryDataset.addValue(579, s, s4);
defaultCategoryDataset.addValue(347, s, s5);
defaultCategoryDataset.addValue(468, s, s6);
defaultCategoryDataset.addValue(2000, s, s7);
return defaultCategoryDataset;
}
private static JFreeChart createChart(CategoryDataset categorydataset) {
String name = "学校生源统计柱状图";
String x_name = "省份";
String y_name = "数量";
System.out.println("name=" + name);
System.out.println("x_name=" + x_name);
//createBarChart3D()只要把这个函数改为3D就可以实现三维效果了,这是与2D惟一的不同之处
JFreeChart jfreechart = ChartFactory.createBarChart3D(name, x_name,
y_name, categorydataset, PlotOrientation.VERTICAL, true, true,
false);
jfreechart.setBackgroundPaint(Color.white);//Color 是paint类型的对象
CategoryPlot categoryplot = jfreechart.getCategoryPlot();
NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
CategoryAxis domainAxis = categoryplot.getDomainAxis();
//定义字体格式
Font font = new Font("微软雅黑", Font.CENTER_BASELINE, 12);
TextTitle title = new TextTitle("Liguokun 李国坤3D图");
//设置标题的格式
title.setFont(font);
//把标题设置到图片里面
jfreechart.setTitle(title);
domainAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 11));
domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12));
numberaxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 12));
numberaxis.setLabelFont(new Font("黑体", Font.PLAIN, 12));
jfreechart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 12));
categoryplot.setDomainGridlinePaint(Color.white);
categoryplot.setDomainGridlinesVisible(true);
categoryplot.setDomainGridlinePaint(Color.BLUE);
// 下面用来让柱图更加好看
BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
barrenderer.setDrawBarOutline(true);
barrenderer.setOutlinePaint(Color.black);//加了个黑边,
barrenderer.setMaximumBarWidth(0.05);
barrenderer.setSeriesFillPaint(0, Color.blue);
return jfreechart;
}
public static String generateBarChart(HttpSession session, PrintWriter pw) {
String filename = "";
CategoryDataset categorydataset = createDataset();//在类里可以调用私有的成员啊
JFreeChart jfreechart = createChart(categorydataset);
ChartRenderingInfo info = new ChartRenderingInfo(
new StandardEntityCollection());
try {
filename = ServletUtilities.saveChartAsPNG(jfreechart, 500, 300,
info, session);
} catch (IOException e) {
e.printStackTrace();
}
try {
ChartUtilities.writeImageMap(pw, filename, info, false);
} catch (IOException e) {
e.printStackTrace();
}
pw.flush();
return filename;
}
}
竖的柱状图
package chart;
import java.awt.Color;
import java.awt.Font;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpSession;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
public class Barchart2DHorizontal {
private static CategoryDataset createDataset() {
String s = "生源省份";//这个就是用于说明图形颜色表的的是什么意思
String s1 = "北京";
String s2 = "天津";
String s3 = "河北";
String s4 = "安徽";
String s5 = "辽宁";
String s6 = "河南";
String s7 = "山东";
DefaultCategoryDataset defaultCategoryDataset = new DefaultCategoryDataset();
defaultCategoryDataset.addValue(2000, s, s1);
defaultCategoryDataset.addValue(600, s, s2);
defaultCategoryDataset.addValue(1200, s, s3);
defaultCategoryDataset.addValue(579, s, s4);
defaultCategoryDataset.addValue(347, s, s5);
defaultCategoryDataset.addValue(468, s, s6);
defaultCategoryDataset.addValue(2000, s, s7);
return defaultCategoryDataset;
}
private static JFreeChart createChart(CategoryDataset categorydataset) {
String name = "学校生源统计柱状图";
String x_name = "省份";
String y_name = "数量";
System.out.println("name=" + name);
System.out.println("x_name=" + x_name);
//竖的变横七竖八的,只要改一个地方PlotOrientation.HORIZONTAL,PlotOrientation.VERTICAL
JFreeChart jfreechart = ChartFactory.createBarChart(name, x_name,
y_name, categorydataset, PlotOrientation.HORIZONTAL, true,
true, false);
jfreechart.setBackgroundPaint(Color.white);//Color 是paint类型的对象
CategoryPlot categoryplot = jfreechart.getCategoryPlot();
NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
CategoryAxis domainAxis = categoryplot.getDomainAxis();
//定义字体格式
Font font = new Font("微软雅黑", Font.CENTER_BASELINE, 12);
TextTitle title = new TextTitle("Liguokun 李国坤2D横向图");
//设置标题的格式
title.setFont(font);
//把标题设置到图片里面
jfreechart.setTitle(title);
domainAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 11));
domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12));
numberaxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 12));
numberaxis.setLabelFont(new Font("黑体", Font.PLAIN, 12));
jfreechart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 12));
categoryplot.setDomainGridlinePaint(Color.white);
categoryplot.setDomainGridlinesVisible(true);
categoryplot.setDomainGridlinePaint(Color.BLUE);
return jfreechart;
}
public static String generateBarChart(HttpSession session, PrintWriter pw) {
String filename = "";
CategoryDataset categorydataset = createDataset();//在类里可以调用私有的成员啊
JFreeChart jfreechart = createChart(categorydataset);
ChartRenderingInfo info = new ChartRenderingInfo(
new StandardEntityCollection());
try {
filename = ServletUtilities.saveChartAsPNG(jfreechart, 500, 300,
info, session);
} catch (IOException e) {
e.printStackTrace();
}
try {
ChartUtilities.writeImageMap(pw, filename, info, false);
} catch (IOException e) {
e.printStackTrace();
}
pw.flush();
return filename;
}
}
多行的柱状图
package chart;
import java.awt.Color;
import java.awt.Font;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpSession;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
public class MutiBarchart2D {
private static CategoryDataset createDataset() {
String boy = "男生人数";//这个就是用于说明图形颜色表的的是什么意思
String girl = "女生人数";
String s1 = "北京";
String s2 = "天津";
String s3 = "河北";
String s4 = "安徽";
String s5 = "辽宁";
String s6 = "河南";
String s7 = "山东";
DefaultCategoryDataset defaultCategoryDataset = new DefaultCategoryDataset();
defaultCategoryDataset.addValue(2000, boy, s1);
defaultCategoryDataset.addValue(600, boy, s2);
defaultCategoryDataset.addValue(1200, boy, s3);
defaultCategoryDataset.addValue(579, boy, s4);
defaultCategoryDataset.addValue(347, boy, s5);
defaultCategoryDataset.addValue(468, boy, s6);
defaultCategoryDataset.addValue(2000, boy, s7);
defaultCategoryDataset.addValue(1300, girl, s1);
defaultCategoryDataset.addValue(607, girl, s2);
defaultCategoryDataset.addValue(1660, girl, s3);
defaultCategoryDataset.addValue(589, girl, s4);
defaultCategoryDataset.addValue(247, girl, s5);
defaultCategoryDataset.addValue(668, girl, s6);
defaultCategoryDataset.addValue(290, girl, s7);
return defaultCategoryDataset;
}
private static JFreeChart createChart(CategoryDataset categorydataset) {
String name = "学校生源统计柱状图";
String x_name = "省份";
String y_name = "数量";
System.out.println("name=" + name);
System.out.println("x_name=" + x_name);
JFreeChart jfreechart = ChartFactory.createBarChart(name, x_name,
y_name, categorydataset, PlotOrientation.VERTICAL, true, true,
false);
jfreechart.setBackgroundPaint(Color.white);//Color 是paint类型的对象
CategoryPlot categoryplot = jfreechart.getCategoryPlot();
NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
CategoryAxis domainAxis = categoryplot.getDomainAxis();
//定义字体格式
Font font = new Font("微软雅黑", Font.CENTER_BASELINE, 12);
TextTitle title = new TextTitle("Liguokun 李国坤多维2D图");
//设置标题的格式
title.setFont(font);
//把标题设置到图片里面
jfreechart.setTitle(title);
domainAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 11));
domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12));
numberaxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 12));
numberaxis.setLabelFont(new Font("黑体", Font.PLAIN, 12));
jfreechart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 12));
categoryplot.setDomainGridlinePaint(Color.white);
categoryplot.setDomainGridlinesVisible(true);
categoryplot.setDomainGridlinePaint(Color.blue);
//下面用来让柱图更加好看
BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
barrenderer.setDrawBarOutline(true);
barrenderer.setOutlinePaint(Color.black);//加了个黑边,
barrenderer.setMaximumBarWidth(0.05);
barrenderer.setSeriesFillPaint(0, Color.blue);
return jfreechart;
}
public static String generateBarChart(HttpSession session, PrintWriter pw) {
String filename = "";
CategoryDataset categorydataset = createDataset();//在类里可以调用私有的成员啊
JFreeChart jfreechart = createChart(categorydataset);
ChartRenderingInfo info = new ChartRenderingInfo(
new StandardEntityCollection());
try {
filename = ServletUtilities.saveChartAsPNG(jfreechart, 500, 300,
info, session);
} catch (IOException e) {
e.printStackTrace();
}
try {
ChartUtilities.writeImageMap(pw, filename, info, false);
} catch (IOException e) {
e.printStackTrace();
}
pw.flush();
return filename;
}
}
发表评论
-
Android 三大图片加载框架比较
2016-11-30 10:31 10781.哪三大图片加载框架? 1) Pi ... -
Java Calendar 类的时间操作
2016-06-01 21:02 661ava Calendar 类时间操作,这也许是创建日历和管理 ... -
获取电脑ip,所在省份城市
2014-08-27 09:45 676调用了腾讯的ip接口(http://fw.qq.com ... -
获取Android签名证书的sha1值
2014-08-23 23:14 657前言:今天开始研 ... -
java中Keytool的使用总结
2014-08-23 22:40 557J2SDK提供了keytool命令行工具,可以根据指定的参数 ... -
Java基础——Java语法基础(3)
2014-06-19 10:13 565程序控制流程 1、顺序结构 按顺序执行 2、i ... -
Java基础——Java语法基础(1)
2014-06-19 10:11 796Java代码基本格式 Java ... -
android MD5校验码的生成与算法实现
2014-06-17 10:58 880在Java中,java.security.Mes ... -
java中的字符串分割函数 split
2014-06-06 15:01 688Java中的我们可以利用sp ... -
java对xml文件做增删改查
2014-06-04 20:40 1834package com.wss; import jav ... -
获取网络的json文件 Gson解析json文件
2013-11-07 16:21 522/** * 获取网络的json文件 * @pa ... -
Java获取文件类型Mime Type的各种方法
2013-09-16 15:46 1138使用 javax.activation.MimetypesF ... -
Java栈与堆
2013-06-20 22:18 9191. 栈(stack)与堆(heap)都 ... -
Android requires compiler compliance level 5.0 or 6.0. Found '1.7' instead.
2013-05-02 12:01 692解决Android requires compiler co ... -
java创建文件和目录
2013-04-25 10:30 599创建文件和目录的关键技术点如下: 1、File类的cr ... -
iava创建文件和目录
2013-04-24 19:42 792创建文件和目录的关键技术点如下: 1、File类的cr ... -
Java程序发送邮件的两种方法
2013-01-25 10:57 1867前一段时间我在博客中发表过Java接收解析邮件的程序 ... -
SharedPreferences保存数据
2013-01-24 15:09 882package com.test; import ja ... -
java 把logcat日志保存到SD里
2013-01-22 20:21 1029private void saveLogcat(){ ... -
Android开发系列:查看LogCat日志
2013-01-19 13:06 3441LogCat日志 1. Window & ...
相关推荐
在"JFreeChart开发全攻略"中,可能包含了以下内容: 1. **环境搭建**:讲解如何在项目中引入JFreeChart库,以及可能需要的其他依赖,如Servlet API等。 2. **创建图表**:介绍如何使用JFreeChart API创建不同类型的...
在Web开发领域,报表技术是不可或缺的一部分,它用于呈现数据并提供可视化的分析结果。JFreeChart是一款强大的Java图表库,适用于生成各种...本实例的资源可以帮助你快速掌握JFreeChart的使用,提升Web报表开发技能。
传统的一些以软件包形式发布应用程序例如报表系统等都在逐渐搬到因特网上。但是这两者之间有着天壤之别,虽然对于数据获取、业务处理等方面...因此我们下面将介绍一个JAVA的图表引擎JFreeChart用来产生基于WEB的图表。
`jfreechart-1.0.13-demo.src` 提供的源代码是学习和研究 JFreeChart 的宝贵资源,通过深入学习这些示例,开发者不仅可以掌握图表的基本创建方法,还能了解如何进行高级定制和优化,提升 Java 图表开发技能。...
### Java报表JFreeChart开发知识点总结 #### 1. 简介 ##### 1.1 什么是JFreeChart JFreeChart是一款免费且开源的Java图表库,它提供了多种类型的图表绘制功能,如饼图、条形图、折线图等。JFreeChart适用于各种Java...
用JFreeChart实现java报表开发(1) 作者:zuoxianghui 来源:blog 整理日期:2007-8-17 jfreechart,到http://www.jfree.org/下载最新的。 一、在web.xml文件中添加: <servlet-name>DisplayChart</servlet-name> ...
JFreeChart是一款强大的Java图表库,它允许开发者创建多种类型的2D图表,如柱状图、饼图、线形图、散点图等,适用于报表、数据分析和可视化应用。1.0.19版本是其稳定的一个版本,包含了丰富的功能和优化。 1. **...
在Web报表开发中,JFreeReport通常与Servlets、JSP或Struts等Web框架结合使用。以下是使用JFreeReport进行Web报表开发的基本步骤: 1. **设计报表模板**:使用JFreeReport提供的Report Designer,可以创建XML格式的...
本文将深入探讨JFreeChart在Java Web开发中的应用及其在报表系统开发中的关键知识点。 首先,JFreeChart支持多种类型的图表,包括柱状图、饼图、线图、面积图、散点图等,这些图表可以满足各种业务场景的数据可视化...
总之,JFreeChart和水晶报表的结合使用,可以帮助开发人员创建具有专业级图表的高质量报告,提升数据分析和决策支持的能力。通过深入学习这两个工具,可以进一步提升在数据可视化和商业智能领域的专业技能。
标题"jfreechart-1.0.19报表工具"表明这是一款基于JFreeChart库的版本1.0.19的报表工具,主要用于数据可视化。 JFreeChart的1.0.19版本可能包含了以下关键特性: 1. **图表类型**:JFreeChart支持多种图表类型,如...
它为开发者提供了丰富的API,使他们能够在Java应用程序、Web应用、报表系统等中方便地集成高质量的图表。"jfreechart-1.0.11-javadocs"是这个库的1.0.11版本的Java文档,它是理解JFreeChart功能和用法的关键资源。 ...
在实际应用中,JFreeChart常与其他Java组件结合使用,比如与Swing或JavaFX进行GUI开发,或者与Spring框架集成,实现服务器端图表生成。这使得JFreeChart在Web应用、桌面应用甚至是移动应用中都能发挥其作用。 总的...
它在Java应用程序、Web应用、报表系统和其他需要可视数据表示的场景中广泛使用。`jfreechart-0.9.16-javadocs` 是该库的API文档,提供了详细的类、接口和方法描述,帮助开发者理解和使用JFreeChart。 1. **类结构与...
JFreeChart支持多种图表类型,包括折线图、柱状图、饼图、散点图、甘特图等,可以用于报表、演示文稿、Web应用等场景。在本demo中,开发者将展示如何使用JFreeChart来创建这三种最常见的图表类型:饼图、柱状图和...
通过学习《精通Java Web动态图表编程》,读者不仅可以掌握JFreeChart的使用,还能了解到Java Web开发的许多重要概念,从而提升开发动态、交互式Web图表的能力。书中的每个章节都是一个逐步进阶的过程,从基础知识到...
本压缩包提供的源码可以作为学习JFreeChart开发的实践案例。通过阅读源码,开发者可以深入了解如何创建和配置图表,以及如何将图表整合到实际项目中。同时,作者提供的联系方式便于进行技术交流和问题解答,这有助于...
在Web开发中,JFreeChart可以帮助开发者生成动态的、交互式的图形报表,使得数据可视化变得更加直观。在这个"Web中JFreeChart图形报表小例子"中,我们将探讨如何在Struts 2.0框架下集成JFreeChart来在JSP页面上展示...
这种动态生成图表的方式对于Web报表来说具有很大的灵活性,可以根据不同的用户请求或者数据库数据实时更新图表,从而提供动态的、交互式的报表体验。 JFreeChart的易用性和丰富的功能使其成为开发图表的理想选择。...
JFreeChart是一款强大的开源图表库,它能够帮助开发者在Java应用程序,尤其是Web应用中创建出各种复杂的图表,显著提升报表的视觉效果和用户交互体验。尽管JFreeChart本身是免费的,但官方提供的支持文档需要付费...