//NewAreachart2D
import java.awt.Color;
import java.io.File;
import javax.servlet.http.HttpServletRequest;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.labels.StandardXYToolTipGenerator;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.data.xy.CategoryTableXYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.RectangleInsets;
public class NewAreachart2D
{
public String getMap(HttpServletRequest request , double bmi)
{
CategoryTableXYDataset one = new CategoryTableXYDataset();
one.add(0D , 3D , "正常1");
one.add(5D , 3D , "正常1");
one.add(5.01D , 9D , "异常2");
one.add(10D , 9D , "异常2");
one.add(10.01D , 15D , "正常3");
one.add(15D , 15D , "正常3");
one.add(15.01D , 21D , "异常4");
one.add(20D , 21D , "异常4");
JFreeChart freechart = ChartFactory.createXYAreaChart("血脂图" , "" , "" , one , PlotOrientation.VERTICAL ,
true , false , false);
freechart.setBorderVisible(false);
XYPlot xyplot = (XYPlot) freechart.getPlot();
xyplot.setBackgroundPaint(Color.WHITE);
xyplot.setAxisOffset(new RectangleInsets(4D , 4D , 4D , 4D));
// 2画BMI值线
java.awt.geom.Ellipse2D.Double two = new java.awt.geom.Ellipse2D.Double(0D , 0D , 0D , 0D);
String curs = "您的值";
XYSeries xyda = new XYSeries(curs);
xyda.add(bmi , 0D);
xyda.add(bmi , 15D);
XYSeriesCollection datasetxy = new XYSeriesCollection();
datasetxy.addSeries(xyda);
XYLineAndShapeRenderer xy = new XYLineAndShapeRenderer();
xyplot.setDataset(1 , datasetxy);
xyplot.setRenderer(1 , xy);
xy.setSeriesShape(0 , two);
xy.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
xy.setSeriesPaint(0 , Color.BLUE);
xy.setSeriesFillPaint(0 , Color.BLUE);
xy.setSeriesOutlinePaint(0 , Color.GREEN);
xy.setUseFillPaint(true);
//y轴的值的设置
NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
numberaxis.setAutoRange(true);
//x轴的值的设置
ValueAxis valueaxis = xyplot.getDomainAxis();
valueaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
valueaxis.setAutoRange(true);
xyplot.setNoDataMessage("没有数据!");
xyplot.setBackgroundPaint(Color.WHITE);
String filename = null;
String root = Generatetime.DIR;
String path = Getinstance.getCurrentTime().getTime();
try
{
File f = new File(root+path+".jpeg");
ChartUtilities.saveChartAsJPEG(f , 1.0f , freechart , 400 , 220);
filename = ServletUtilities.saveChartAsJPEG(freechart , 400 , 220 , request.getSession());
}
catch (Exception e)
{
System.out.println(e.toString());
}
String grapUrl = request.getContextPath()+"/show?filename="+filename;
return grapUrl;
}
}
//Morebarchart2D
import java.io.File;
import javax.servlet.http.HttpServletRequest;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.SubCategoryAxis;
import org.jfree.chart.labels.ItemLabelAnchor;
import org.jfree.chart.labels.ItemLabelPosition;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.GroupedStackedBarRenderer;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.data.KeyToGroupMap;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.TextAnchor;
/**
* @author huangtao
*
*/
public class Morebarchart2D
{
public String getMap(HttpServletRequest request)
{
DefaultCategoryDataset ddataset = new DefaultCategoryDataset();
ddataset.addValue(3D, "正常", "总胆固醇");
ddataset.addValue(7D, "异常", "总胆固醇");
ddataset.addValue(2.8D, "您的数值", "总胆固醇");//总胆固醇数值
ddataset.addValue(2D, "正常", "甘油三脂");
ddataset.addValue(8D, "异常", "甘油三脂");
ddataset.addValue(3.6D, "您的数值", "甘油三脂");//甘油三脂数值
ddataset.addValue(8D, "正常", "高密度脂蛋白");
ddataset.addValue(2D, "异常", "高密度脂蛋白");
ddataset.addValue(1.8D, "您的数值", "高密度脂蛋白");//高密度脂蛋白数值
ddataset.addValue(3.1D, "正常", "低密度脂蛋白");
ddataset.addValue(6.9D, "异常", "低密度脂蛋白");
ddataset.addValue(4.4D, "您的数值", "低密度脂蛋白");//低密度脂蛋白数值
JFreeChart jfreechart = ChartFactory.createStackedBarChart("血脂图", "种类", "mmol/l", ddataset, PlotOrientation.VERTICAL, true, false, false);
GroupedStackedBarRenderer gone = new GroupedStackedBarRenderer();
KeyToGroupMap keyone = new KeyToGroupMap("总胆固醇");
keyone.mapKeyToGroup("正常", "总胆固醇");
keyone.mapKeyToGroup("异常", "总胆固醇");
keyone.mapKeyToGroup("您的数值", "您的总胆固醇数值");
keyone.mapKeyToGroup("正常", "甘油三脂");
keyone.mapKeyToGroup("异常", "甘油三脂");
keyone.mapKeyToGroup("您的数值", "您的甘油三脂数值");
keyone.mapKeyToGroup("正常", "高密度脂蛋白");
keyone.mapKeyToGroup("异常", "高密度脂蛋白");
keyone.mapKeyToGroup("您的数值", "您的高密度脂蛋白数值");
keyone.mapKeyToGroup("正常", "低密度脂蛋白");
keyone.mapKeyToGroup("异常", "低密度脂蛋白");
keyone.mapKeyToGroup("您的数值", "您的低密度脂蛋白数值");
gone.setSeriesToGroupMap(keyone);
gone.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
gone.setBaseItemLabelsVisible(true);
gone.setPositiveItemLabelPositionFallback(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.TOP_LEFT));
gone.setItemMargin(0.09D);
gone.setMaximumBarWidth(0.09D);
//添加子标题
SubCategoryAxis subcategoryaxis = new SubCategoryAxis("血脂图");
subcategoryaxis.setCategoryMargin(0.10D);
//显示相应项的值
CategoryPlot categoryplot = (CategoryPlot)jfreechart.getPlot();
categoryplot.setDomainAxis(subcategoryaxis);
categoryplot.setRenderer(gone);
String filename = null;
String root = Generatetime.DIR;
String path = Getinstance.getCurrentTime().getTime();
try
{
File f = new File(root+path+".jpeg");
ChartUtilities.saveChartAsJPEG(f , 1.0f , jfreechart , 360 , 240);
filename = ServletUtilities.saveChartAsJPEG(jfreechart , 360 , 240 , request.getSession());
}
catch (Exception e)
{
System.out.println(e.toString());
}
String grapUrl = request.getContextPath()+"/show?filename="+filename;
return grapUrl;
}
}
//Hbbarchart2D
import java.awt.Color;
import java.awt.Font;
import java.io.File;
import java.text.NumberFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import javax.servlet.http.HttpServletRequest;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.SubCategoryAxis;
import org.jfree.chart.labels.ItemLabelAnchor;
import org.jfree.chart.labels.ItemLabelPosition;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.TextAnchor;
/**
* @author huangtao
*
*/
public class Hbbarchart2D
{
public String getMap(HttpServletRequest request)
{
//乙肝抽查的各项指标
String[] str = {"HbsAg" , "HbsAb" , "HbeAg" , "HbeAb" , "HbcAb"};
//各项指标的对应的结果
String[] result={"+".toUpperCase(),"+".toUpperCase(),"-".toUpperCase(),"-".toUpperCase(),"+".toUpperCase()};
Map<String , String> hbMap = new HashMap<String , String>();
for(int i = 0 ; i<5 ; i++)
{
hbMap.put(str[i] , result[i]);
}
//结果集
DefaultCategoryDataset ddataset = new DefaultCategoryDataset();
for(int i = 0 ; i<hbMap.size() ; i++)
{
ddataset.addValue(0.05 , result[i] , str[i]);
}
//画图的工厂类
JFreeChart jfreechart = ChartFactory.createStackedBarChart("乙肝五项分析值" , "指标分析项" , "阴性(-)/阳性(+)" , ddataset ,
PlotOrientation.HORIZONTAL , false , true , false);
jfreechart.addSubtitle(new TextTitle("Source:http://www.guokang.com/", new Font("Dialog", 2, 12)));
jfreechart.setBackgroundImageAlpha(1.0f);
jfreechart.setBackgroundPaint(Color.WHITE);
CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
CategoryItemRenderer cirender = categoryplot.getRenderer();
//相关项在坐标轴上的显示位置
ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.CENTER , TextAnchor.CENTER ,
TextAnchor.CENTER , 0.0D);
StandardCategoryItemLabelGenerator standardcategoryitemlabelgenerator = new StandardCategoryItemLabelGenerator(
"{0}" , NumberFormat.getInstance());
cirender.setBasePositiveItemLabelPosition(itemlabelposition);
cirender.setBaseItemLabelGenerator(standardcategoryitemlabelgenerator);
cirender.setBaseItemLabelsVisible(true);
categoryplot.setNoDataMessage("无该数据!");
//添加子标题
String filename = null;
String root = Generatetime.DIR;
String path = Getinstance.getCurrentTime().getTime();
try
{
File f = new File(root+path+".jpeg");
ChartUtilities.saveChartAsJPEG(f , 1.0f , jfreechart , 360 , 240);
filename = ServletUtilities.saveChartAsJPEG(jfreechart , 360 , 240 , request.getSession());
}
catch (Exception e)
{
System.out.println(e.toString());
}
String grapUrl = request.getContextPath()+"/show?filename="+filename;
return grapUrl;
}
}
//NewAreachart2D1
import java.awt.Color;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.servlet.http.HttpServletRequest;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.labels.StandardXYToolTipGenerator;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.data.xy.CategoryTableXYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.RectangleInsets;
public class NewAreachart2D1
{
public String getMap(HttpServletRequest request,double[] value)
{
CategoryTableXYDataset one = new CategoryTableXYDataset();
one.add(60D , 120D , "理想");
one.add(80D , 120D , "理想");
one.add(80.01D , 130D , "正常");
one.add(85D , 130D , "正常");
one.add(85.01D , 140D , "正常高值");
one.add(90D , 140D , "正常高值");
one.add(90.01D , 150D , "高血压");
one.add(100D , 150D , "高血压");
JFreeChart freechart = ChartFactory.createXYAreaChart("" , "舒张压"+value[0] , "收缩压"+value[1] , one , PlotOrientation.VERTICAL ,
true , false , false);
freechart.setBorderVisible(false);
XYPlot xyplot = (XYPlot) freechart.getPlot();
xyplot.setBackgroundPaint(Color.WHITE);
xyplot.setDomainGridlinesVisible(true);
xyplot.setDomainZeroBaselineVisible(true);
xyplot.setForegroundAlpha(1.0f);
xyplot.setAxisOffset(new RectangleInsets(4D , 4D , 4D , 4D));
// 2画BMI值线
java.awt.geom.Ellipse2D.Double two = new java.awt.geom.Ellipse2D.Double(0D , 0D , 6D , 5D);
String curs = "您的值";
XYSeries xyda = new XYSeries(curs);
xyda.add(value[0] , 0D);
xyda.add(value[0] , value[1]);
XYSeriesCollection datasetxy = new XYSeriesCollection();
datasetxy.addSeries(xyda);
XYLineAndShapeRenderer xy = new XYLineAndShapeRenderer();
xyplot.setDataset(1 , datasetxy);
xyplot.setRenderer(1 , xy);
xy.setSeriesShape(0 , two);
xy.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
xy.setSeriesPaint(0 , Color.DARK_GRAY);
// xy.setSeriesFillPaint(0 , Color.PINK);
// xy.setSeriesOutlinePaint(0 , Color.YELLOW);
xy.setUseFillPaint(true);
//y轴的值的设置
NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
numberaxis.setLowerBound(90D);
numberaxis.setLowerMargin(10D);
numberaxis.setUpperBound(150D);
//x轴的值的设置
ValueAxis valueaxis = xyplot.getDomainAxis();
valueaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
valueaxis.setLowerBound(60D);
valueaxis.setLowerMargin(5D);
valueaxis.setUpperBound(100D);
xyplot.setNoDataMessage("没有数据!");
xyplot.setBackgroundPaint(Color.WHITE);
String filename = null;
String root = Generatetime.DIR;
String path = Getinstance.getCurrentTime().getTime();
try
{
File f = new File(root+path+".jpeg");
//使生成的图形可以旋转
// BufferedImage bi=freechart.createBufferedImage(400 , 220);
// AffineTransform tx =AffineTransform.getScaleInstance(-1, -1);
// tx.translate(20D, 20D);
// AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
// op.filter(bi, null);
ChartUtilities.saveChartAsJPEG(f , 1.0f , freechart , 400 , 220);
filename = ServletUtilities.saveChartAsJPEG(freechart , 400 , 220 , request.getSession());
}
catch (Exception e)
{
System.out.println(e.toString());
}
String grapUrl = request.getContextPath()+"/show?filename="+filename;
return grapUrl;
}
}
//jsp页面
<%@ page language="java" pageEncoding="UTF-8"
contentType="text/html; charset=gb2312" session="true"%>
<%@ include file="/common/title.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>图象显示页面</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<%--<form action="<%=request.getContextPath()%>/barchart.do" name="chart"
method="post">
<table>
<tr>
<td>
<input type="radio" name="pa" size="4" value="1">
A1
</td>
<td>
<input type="radio" name="pa" size="4" value="2">
B1
</td>
<td>
<input type="radio" name="pa" size="4" value="3">
C1
</td>
</tr>
<tr>
<td>
<input type="radio" name="ba" size="4" value="4">
A2
</td>
<td>
<input type="radio" name="ba" size="4" value="5">
B2
</td>
<td>
<input type="radio" name="ba" size="4" value="6">
C2
</td>
</tr>
<tr>
<td>
<input type="radio" name="wa" size="4" value="7">
A3
</td>
<td>
<input type="radio" name="wa" size="4" value="8">
B3
</td>
<td>
<input type="radio" name="wa" size="4" value="9">
C3
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</form>
--%><form action="<%=request.getContextPath()%>/barchart.do" name="chart"
method="post">
<input type="hidden" name="method" value="piechart2D" size="8">
<input type="submit" name="piechart2D" value="2D饼图" size="8"
onclick="method.value='piechart2D'">
<input type="submit" name="barchart2D" value="2D柱状图" size="8"
onclick="method.value='barchart2D'">
<input type="submit" name="areachart2D" value="2D区域图" size="8"
onclick="method.value='areachart2D'">
<input type="submit" name="newarea2D" value="新2D区域图" size="8"
onclick="method.value='newarea2D'">
<input type="submit" name="piechart3D" value="3D饼图" size="8"
onclick="method.value='piechart3D'">
<input type="submit" name="simplepie3D" value="简单3D饼图" size="8"
onclick="method.value='simplepie3D'">
<input type="submit" name="barchart3D" value="3D柱状图" size="8"
onclick="method.value='barchart3D'">
<input type="submit" name="morebarchart2D" value="层叠柱状图" size="8"
onclick="method.value='morebarchart2D'">
<input type="submit" name="hbbarchart2D" value="乙肝体检图" size="8"
onclick="method.value='hbbarchart2D'">
<input type="submit" name="test" value="test" size="8"
onclick="method.value='test'">
</form>
<table align="center">
<logic:present name="simplepie3D">
<img src="${simplepie3D}" border="0" usemap="#map0">
</logic:present>
<logic:present name="piechart2D">
<img src="${piechart2D}" border="0" usemap="#map0">
</logic:present>
<logic:present name="piechart3D">
<img src="${piechart3D}" border="0" usemap="#map0">
</logic:present>
<logic:present name="barchart2D">
<img src="${barchart2D}" border="0" usemap="#map0">
</logic:present>
<logic:present name="barchart3D">
<img src="${barchart3D}" border="0" usemap="#map0">
</logic:present>
<logic:present name="areachart2D">
<img src="${areachart2D}" border="0" usemap="#map0">
</logic:present>
<logic:present name="newarea2D">
<img src="${newarea2D}" border="0" usemap="#map0">
</logic:present>
</table>
<%--<table>
<tr>
<td class="pt9">
<div align="center">
验证码:
<img title="如看不清验证码,请点击图案" alt="用户登陆的图形验证码" align="top" border="1"
ismap="ismap" dir="ltr" src="loginCheck"
onclick="checkthree.src='loginCheck'" name="checkthree">
</div>
</td>
</tr>
</table>
--%></body>
</html>
//打印
<%@ page language="java" pageEncoding="UTF-8"
contentType="text/html; charset=gb2312" session="false"%>
<%@ include file="/common/title.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'test.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="" type="text/css" href="chart.css">
<style media=print>
.Noprint{display:none;}
.PageNext{page-break-after: always;}
</style>
<script type="text/javascript">
function runClose()
{
if(window.confirm("你确定要关闭本窗口吗?"))
{
window.self.close();
}
window.location.href="<%=request.getContextPath()%>/jsp/PrintChart.jsp";
}
</script>
</head>
<body oncontextmenu=return(false)>
<center class="Noprint">
<p style="background-color:#e7f3ff;">
<OBJECT id=WebBrowser
classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0>
</OBJECT>
<input type="button" value="页面设置"
onclick="document.all.WebBrowser.ExecWB(8,1)">
<input type="button" value="打印预览"
onclick="document.all.WebBrowser.ExecWB(7,1)">
</p>
<p style="background-color:#e7f3ff;">
<input type="button" value=" 打 印 "
onclick="document.all.WebBrowser.ExecWB(6,1)">
<input type="button" value=" 返 回 "
onclick="javascript:window.location.href='<%=request.getContextPath()%>/jsp/test.jsp'">
</p>
<p style="background-color:#e7f3ff;">
<input type="button" value="关闭窗口" onclick="runClose();">
</p>
<hr align="center" width="90%" size="1" noshade>
</center>
<table align="center" oncontextmenu=return(false)>
<logic:present name="simplepie3D">
<img src="${simplepie3D}" border="0" usemap="#map0" vspace="10">
</logic:present>
<logic:present name="piechart2D">
<img src="${piechart2D}" border="0" usemap="#map0">
</logic:present>
<logic:present name="piechart3D">
<img src="${piechart3D}" border="0" usemap="#map0">
</logic:present>
<logic:present name="barchart2D">
<img src="${barchart2D}" border="0" usemap="#map0">
</logic:present>
<logic:present name="barchart3D">
<img src="${barchart3D}" border="0" usemap="#map0">
</logic:present>
<logic:present name="areachart2D">
<img src="${areachart2D}" border="0" usemap="#map0">
</logic:present>
<logic:present name="newarea2D">
<img src="${newarea2D}" border="0" usemap="#map0">
</logic:present>
<logic:present name="morebarchart2D">
<img src="${morebarchart2D}" border="0" usemap="#map0" align="right">
</logic:present>
<logic:present name="hbbarchart2D">
<img src="${hbbarchart2D}" border="0" usemap="#map0" align="right">
</logic:present>
<logic:present name="test">
<img src="${test}" border="0" usemap="#map0" align="right">
</logic:present>
</table>
</body>
</html>