jfc在jsp页面画图,不将图片存在服务器端,只存入会话session(可用)
jfc在jsp页面画图,不将图片存在服务器端,只存入会话session。其中主要用到jfc的一个servlet类。
<%@ page contentType="text/html;charset=gb2312" errorPage="../common/error.jsp" %>
<%@ page import="dqz.jsp.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.*" %>
<%@ page import="javax.naming.*" %>
<%@ include file="../common/config.jsp"%>
<%@ include file="reporter_session.jsp"%>
<%@ page import="
org.jfree.chart.servlet.ServletUtilities,
java.awt.Font,
java.awt.Color,
org.jfree.chart.ChartFactory,
org.jfree.chart.ChartFrame,
org.jfree.chart.JFreeChart,
org.jfree.chart.StandardChartTheme,
org.jfree.chart.plot.CategoryPlot,
org.jfree.chart.plot.PlotOrientation,
org.jfree.data.category.CategoryDataset,
org.jfree.data.category.DefaultCategoryDataset,
org.jfree.chart.ChartUtilities,
org.jfree.chart.axis.CategoryAxis,
org.jfree.chart.axis.NumberAxis,
org.jfree.chart.axis.ValueAxis,
org.jfree.chart.labels.StandardCategoryItemLabelGenerator,
org.jfree.chart.renderer.category.BarRenderer,
org.jfree.chart.title.TextTitle, java.io.FileOutputStream,
java.io.IOException, java.io.PrintWriter,
java.util.ArrayList, java.util.HashMap, java.util.List,
java.util.Map,
java.text.DecimalFormat,
java.text.NumberFormat,
java.io.FileOutputStream,
java.io.IOException,
java.io.PrintWriter,
java.sql.Connection,
java.sql.DriverManager,
java.sql.PreparedStatement,
java.sql.ResultSet,
java.sql.SQLException,
java.util.ArrayList,
java.util.List,
org.jfree.chart.servlet.ServletUtilities,
java.util.Map,
org.jfree.chart.labels.StandardPieSectionLabelGenerator,
org.jfree.chart.labels.StandardPieToolTipGenerator,
org.jfree.chart.plot.PiePlot3D,
org.jfree.data.general.DefaultPieDataset,
org.jfree.data.general.PieDataset,
org.jfree.chart.title.LegendTitle "%> //===========================直方图测试开始===================================================
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(610, "广州", "猪肉");
dataset.addValue(220, "广州", "牛肉");
dataset.addValue(530, "广州", "鸡肉");
dataset.addValue(340, "广州", "鱼肉"); JFreeChart mBarChart = ChartFactory.createBarChart3D("肉类销量统计图",
"肉类",
"销量",
dataset,
PlotOrientation.VERTICAL,
false,
false,
false); //图表标题设置
TextTitle mTextTitle = mBarChart.getTitle();
mTextTitle.setFont(new Font("黑体", Font.BOLD, 20));
//mBarChart.setTitle(new TextTitle("学校人员分布图",new Font("黑体", Font.BOLD, 20)));
//图表图例设置
LegendTitle mLegend = mBarChart.getLegend();
if(mLegend != null)
mLegend.setItemFont(new Font("宋体", Font.CENTER_BASELINE, 15));
//mBarChart.getLegend().setItemFont(new Font("宋体", Font.CENTER_BASELINE, 15));
//设置柱状图轴
CategoryPlot mPlot = (CategoryPlot)mBarChart.getPlot(); //x轴
CategoryAxis mDomainAxis = mPlot.getDomainAxis();
//设置x轴标题的字体
mDomainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 15));
//设置x轴坐标字体
mDomainAxis.setTickLabelFont(new Font("宋体", Font.PLAIN, 15));
//y轴
ValueAxis mValueAxis = mPlot.getRangeAxis();
//设置y轴标题字体
mValueAxis.setLabelFont(new Font("宋体", Font.PLAIN, 15));
//设置y轴坐标字体
mValueAxis.setTickLabelFont(new Font("宋体", Font.PLAIN, 15));
//柱体显示数值
BarRenderer mRenderer= new BarRenderer();
mRenderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
mRenderer.setItemLabelFont(new Font("宋体", Font.PLAIN, 10));
mRenderer.setItemLabelsVisible(true);
mPlot.setRenderer(mRenderer); String filename = ServletUtilities.saveChartAsPNG(mBarChart, 800, 400, null, session);
String graphURL = request.getContextPath() + "/DisplayChart?filename=" + filename; //===========================直方图测试结束=================================================== //===========================饼图测试开始=================================================== //设置数据源
DefaultPieDataset mpieDataset = new DefaultPieDataset();
mpieDataset.setValue(" 市场前期", new Double(10));
mpieDataset.setValue(" 立项", new Double(15));
mpieDataset.setValue(" 计划", new Double(20));
mpieDataset.setValue(" 需求与设计", new Double(10));
mpieDataset.setValue(" 执行控制", new Double(25));
mpieDataset.setValue(" 收尾", new Double(10));
mpieDataset.setValue(" 运维",new Double(10)); //建立图表
JFreeChart mpieChart = ChartFactory.createPieChart3D("项目进度分布", mpieDataset, true, true, false);
//设置图表标题
mpieChart.setTitle(new TextTitle("项目状态分布", new Font("黑体",Font.CENTER_BASELINE, 20)));
//设置Legend字体
mpieChart.getLegend().setItemFont(new Font("宋体", Font.ROMAN_BASELINE, 15)); PiePlot3D mPiePlot = (PiePlot3D)mpieChart.getPlot();
//以默认方式显示百分比
//mPiePlot.setLabelGenerator(new StandardPieSectionLabelGenerator(StandardPieToolTipGenerator.DEFAULT_TOOLTIP_FORMAT));
// 图片中显示百分比:自定义方式,{0} 表示选项, {1} 表示数值, {2} 表示所占比例 ,小数点后两位
mPiePlot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})", NumberFormat.getNumberInstance(), new DecimalFormat("0.00%")));
// 底部图例显示百分比:自定义方式, {0} 表示选项, {1} 表示数值, {2} 表示所占比例
mPiePlot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})"));
//设置饼图标签字体
mPiePlot.setLabelFont(new Font("宋体", Font.PLAIN, 15)); String piefilename = ServletUtilities.saveChartAsPNG(mpieChart, 800, 400, null, session);
String piegraphURL = request.getContextPath() + "/DisplayChart?filename=" + piefilename;
//===========================饼图测试结束=================================================== //===========================折线图测试开始=================================================== StandardChartTheme mChartThemezxt = new StandardChartTheme("CN");
mChartThemezxt.setLargeFont(new Font("黑体", Font.BOLD, 20));
mChartThemezxt.setExtraLargeFont(new Font("宋体", Font.PLAIN, 15));
mChartThemezxt.setRegularFont(new Font("宋体", Font.PLAIN, 15));
ChartFactory.setChartTheme(mChartThemezxt); // row keys...
String series1 = "First";
String series2 = "Second";
String series3 = "Third"; // column keys...
String type1 = "Type 1";
String type2 = "Type 2";
String type3 = "Type 3";
String type4 = "Type 4";
String type5 = "Type 5";
String type6 = "Type 6";
String type7 = "Type 7";
String type8 = "Type 8"; // create the dataset...
DefaultCategoryDataset dataset_zxt = new DefaultCategoryDataset(); dataset_zxt.addValue(1.0, series1, type1);
dataset_zxt.addValue(4.0, series1, type2);
dataset_zxt.addValue(3.0, series1, type3);
dataset_zxt.addValue(5.0, series1, type4);
dataset_zxt.addValue(5.0, series1, type5);
dataset_zxt.addValue(7.0, series1, type6);
dataset_zxt.addValue(7.0, series1, type7);
dataset_zxt.addValue(0.0, series1, type8); dataset_zxt.addValue(5.0, series2, type1);
dataset_zxt.addValue(7.0, series2, type2);
dataset_zxt.addValue(6.0, series2, type3);
dataset_zxt.addValue(8.0, series2, type4);
dataset_zxt.addValue(4.0, series2, type5);
dataset_zxt.addValue(4.0, series2, type6);
dataset_zxt.addValue(2.0, series2, type7);
dataset_zxt.addValue(1.0, series2, type8); dataset_zxt.addValue(4.0, series3, type1);
dataset_zxt.addValue(3.0, series3, type2);
dataset_zxt.addValue(2.0, series3, type3);
dataset_zxt.addValue(3.0, series3, type4);
dataset_zxt.addValue(6.0, series3, type5);
dataset_zxt.addValue(3.0, series3, type6);
dataset_zxt.addValue(4.0, series3, type7);
dataset_zxt.addValue(3.0, series3, type8); JFreeChart mzxtChart = ChartFactory.createLineChart(
"折线图",
"时间",
"数量",
dataset_zxt,
PlotOrientation.VERTICAL,
true,
true,
false); CategoryPlot mzxtPlot = (CategoryPlot)mzxtChart.getPlot();
mzxtPlot.setBackgroundPaint(Color.LIGHT_GRAY);
mzxtPlot.setRangeGridlinePaint(Color.BLUE);//背景底部横虚线
mzxtPlot.setOutlinePaint(Color.RED);//边界线
mzxtChart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 12));//图列 CategoryAxis mzxtdomainAxis = mzxtPlot.getDomainAxis(); //X坐标
mzxtdomainAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 11)); //X
mzxtdomainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12)); ValueAxis mzxtValueAxis = mzxtPlot.getRangeAxis();
mzxtValueAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 12)); //Y
mzxtValueAxis.setLabelFont(new Font("黑体", Font.PLAIN, 12)); TextTitle zxttextTitle = mzxtChart.getTitle();//坐标标题设置
zxttextTitle.setFont(new Font("黑体", Font.PLAIN, 20)); String zxtfilename = ServletUtilities.saveChartAsPNG(mzxtChart, 800, 400, null, session);
String zxtgraphURL = request.getContextPath() + "/DisplayChart?filename=" + zxtfilename;
//===========================折线图测试结束=================================================== %> <img src="<%= graphURL %>" width=800 height=400 border=0 usemap="#<%= filename %>">
<br/>
<img src="<%= piegraphURL %>" width=800 height=400 border=0 usemap="#<%= piefilename %>">
<br/>
<img src="<%= zxtgraphURL %>" width=800 height=400 border=0 usemap="#<%= zxtfilename %>">
jfc在jsp页面画图,不将图片存在服务器端,只存入会话session(可用)的更多相关文章
- JSP 页面跳转中的参数传递
1. 从一个 JSP 页面跳转到另一个 JSP 页面时的参数传递 1)使用 request 内置对象获取客户端提交的信息 2)使用 session 对象获取客户端提交的信息 3)利用隐藏域传递数据 4 ...
- JSP页面中文乱码问题
$.get()方法到服务器端中文乱码 在jsp页面使用encodeURI(“中文”),在服务器端进行解码 String name = req.getParameter("name" ...
- JSP页面+请求转发+EL表达式
1) JSP全称Java Server Pages,顾名思义就是运行在java服务器中的页面,也就是在我们JavaWeb中的动态页面,其本质就是一个Servlet.2) 其本身是一个动态网页技术标准, ...
- 将jsp页面转化为图片或pdf(一)
在项目中遇见了将jsp页面转化为pdf的问题,试过itext,但是itext需要标准的html代码,我的页面中的一些属性是itext所不识别的,所以努力了一段时间后就放弃了,后来发现htmlutil抓 ...
- JSP 页面中插入图片
第一步 在 JSP 页面中插入图片 EL 表达式 ${pageContext.request.contextPath } 的值为当前的项目名称 <html> ... <body> ...
- JSP 页面中用绝对路径显示图片
首先,图片和工程不在一个盘符下.图片也不能放到工程下. 在JSP 文件中 <img src="E:/图片/1.jpg"/> 这样是引不到图片的.因为,JSP页面在引 ...
- jsp页面图片显示不出来
jsp页面就是MyJsp.jsp <body> This is my JSP page. <br> <img src="img/top.jpg"> ...
- java 通过流的方式读取本地图片并显示在jsp 页面上(类型以jpg、png等结尾的图片)
Java代码: File filePic = new File(path+"1-ab1.png"); if(filePic.exists()){ FileInputStream i ...
- 将jsp页面转化为图片或pdf升级版(二)(qq:1324981084)
java高级架构师全套vip教学视频,需要的加我qq1324981084 上面我们已经将jsp页面转化成html页面了,那么接下来我们的目标是利用这个html页面形成pdf或图片格式.这里我用到的是w ...
随机推荐
- ElasticSearch(六) Elasticsearch在Thinkphp5.0中的使用
首先下载需要引入的类库 链接:https://pan.baidu.com/s/1XEXviLoWM-ypwJ_B0jXqlg 密码:u54t //Elasticsearch.zip类库压缩包地址 然后 ...
- asp.net操作GridView添删改查的两种方法 及 光棒效果
这部份小内容很想写下来了,因为是基础中的基础,但是近来用的比较少,又温习了一篇,发现有点陌生了,所以,还是写一下吧. 方法一:使用Gridview本身自带的事件处理,代码如下(注意:每次操作完都得重新 ...
- 20145327高晨 实验一 "Java开发环境的熟悉"
实验一 Java开发环境的熟悉(Linux + Eclipse) (Windows + IDEA) 实验内容:实现Fibonacci数列功能,并进行测试. 实验步骤: Fibonacci数列(斐波拉契 ...
- Linux禁止普通用户使用crontab命令
cron计划任务默认root用户与非root用户都可以执行,当然如果在安全方面想禁用这部分用户,则可以通过两个文件来解决: cron.allow cron.deny cron.allow:定义允许使用 ...
- SSH免密码登录Linux
如果两台linux之间交互频繁,但是每次交互如果都需要输入密码,就会很麻烦,通过配置SSH就可以解决这一问题 下面就说下配置流程(下面流程在不同机器上全部操作一边) 1)cd ~到这个目录中 2)ss ...
- 2017 ACM/ICPC 南宁区 网络赛 Overlapping Rectangles
2017-09-24 20:11:21 writer:pprp 找到的大神的代码,直接过了 采用了扫描线+线段树的算法,先码了,作为模板也不错啊 题目链接:https://nanti.jisuanke ...
- LIS学习笔记(两种算法)O(n^2) 和 O(nlogn)
2017-09-02 10:34:21 writer:pprp 最长上升子序列,具体分析看代码:O(n^2)的做法,dp的思想 分析:每次读一个进行扫描,如果当前读入的这个要比之前的大, 说明有可能加 ...
- js事件在不同浏览器之间的差异
目录: 1. 介绍 2. 不同浏览器之间的差异 2.1 添加事件的方法 2.2 事件对象event 2.3 event中的属性/方法 3. 总结 1. 介绍 javascript与HTML之间的交互是 ...
- char数组
*****************************************************************char 类型的数组(c语言中是没有字符串的)char name[20 ...
- 英语每日写作---4、VOA慢速英语(翻译+字幕+讲解):专家:城市发展将加剧住房危机
英语每日写作---4.VOA慢速英语(翻译+字幕+讲解):专家:城市发展将加剧住房危机 一.总结 一句话总结: takes place 发生deal with 处理:应付population grow ...