jfreechart开发体温单
之前在网上搜索用jfreechat怎么开发体温单这类复杂的图形报表。无奈网上资源少,没有办法,只能自己硬着头皮、慢慢摸索,最终才磕磕碰碰的做出来了。
把体温单的样式贴出来.
点击打开链接
现把代码上传
/**
* Chart基类
*/
public abstract class BaseChart
{
//背景图片
protected Image bgImg;
//子标题列表
protected List<TextTitle> textTitleList;
/**
* 添加子标题, 要在继承类中实现这个方法并且在画图之前调用它<br>
* 会用到子标题列表 textTitleList
* @param chart
*/
protected abstract void addTitle(JFreeChart chart);
/**
* 设置背景图片, 要在继承类中实现这个方法并且在画图之前调用它<br>
* 会用到背景图片对象bgImg
* @param plot
*/
protected abstract void setBgImg(Plot plot);
/**
* 设置曲线图的背景图片
* <pre>setBackgroundImg("images/bg.gif")</pre>
* @param fileName 文件名
* @throws Exception
*/
public void setBackgroundImg(HttpServletRequest request,String fileName) throws Exception
{
ImageIcon icon = new ImageIcon(request.getSession().getServletContext().getRealPath("/images"+fileName));
bgImg = icon.getImage();
}
/**
* 添加子标题
* @param title
*/
public void addSubtitle(String title)
{
Font font = new Font("隶书", Font.PLAIN, 15);
this.addSubtitle(title, font);
}
/**
* 添加子标题并设置标题为指定字体
* @param title
* @param font
*/
public void addSubtitle(String title, Font font)
{
if(title == null )
return;
if(textTitleList == null)
textTitleList = new ArrayList<TextTitle>();
if(font == null)
font = new Font("隶书", Font.PLAIN, 15);
TextTitle tt = new TextTitle(title, font);
textTitleList.add(tt);
}
}
/***
* Chart实体类
*/
public class ChartBean
{
private XYSeries series;
private int index; //线的索引
private Shape shape;//线上点的形状
private Color shapeColor;// 线上点的颜色
private Boolean shapeFilled; //是否填充点
private Color lineColor;//线的颜色
private Boolean lineVisible; //线是否可见
private Boolean shapeVisible; //线上点是否可见
private Boolean lineDash; //线是否是虚线
private Float lineWidth; //线的宽度
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
public XYSeries getSeries() {
return series;
}
public void setSeries(XYSeries series) {
this.series = series;
}
public Shape getShape() {
return shape;
}
public void setShape(Shape shape) {
this.shape = shape;
}
public Color getShapeColor() {
return shapeColor;
}
public void setShapeColor(Color shapeColor)
{
this.shapeColor = shapeColor;
}
public Color getLineColor()
{
return lineColor;
}
public void setLineColor(Color lineColor) {
this.lineColor = lineColor;
}
public Boolean getShapeVisible()
{
if(this.shapeVisible == null)
return true;
return shapeVisible;
}
public void setShapeVisible(Boolean shapeVisible)
{
this.shapeVisible = shapeVisible;
}
public Boolean getShapeFilled()
{
if(shapeFilled == null)
return false;
return shapeFilled;
}
public void setShapeFilled(Boolean shapeFilled) {
this.shapeFilled = shapeFilled;
}
public Boolean getLineVisible() {
return lineVisible;
}
public void setLineVisible(Boolean lineVisible) {
this.lineVisible = lineVisible;
}
public Boolean getLineDash() {
return lineDash;
}
public void setLineDash(Boolean lineDash) {
this.lineDash = lineDash;
}
public Float getLineWidth() {
return lineWidth;
}
public void setLineWidth(Float lineWidth) {
this.lineWidth = lineWidth;
}
/**
* 获得线的笔触
* @return
*/
public Stroke getLineStroke()
{
if(this.lineWidth == null)
lineWidth = ChartShape.LINE_THIN;
if(this.lineDash == null)
{
lineDash = new Boolean(false);
}
return ChartShape.getLineStoke(lineWidth, this.lineDash);
}
}
/**
Chart形状
*/
public class ChartShape
{
public static int ROUND = 1; //圆
public static int RECTANGLE = 2;// 矩形
public static int LINE = 3; //线
public static int TRIANGLE = 4; //三角形
public static float LINE_TINY = 0.7f; //线的粗细(最细)
public static float LINE_THIN = 1.0f; //线的粗细(细)
public static float LINE_NORMAL = 1.5f; //线的粗细(一般)
public static float LINE_WIDE = 2.0f; //线的粗细(宽)
public static float LINE_BOLD = 3.0f; //线的粗细(最宽)
public static Shape getShape(Integer shape)
{
return getShape(shape, 8, 8);
}
public static Shape getShape(int shape, double width, double height)
{
if(shape == ROUND)
{
return new Ellipse2D.Double(-width/2 ,-height/2, width, height);
}
if(shape == RECTANGLE)
{
return new Rectangle2D.Double(0,0, width, height);
}
if(shape == TRIANGLE)
{
int w = new Double(width).intValue();
Polygon poly = new Polygon();
poly.addPoint(0, - 2 * w);
poly.addPoint(-w, 0);
poly.addPoint(w, 0);
return poly;
}
return new Ellipse2D.Double(0,0, width, height);
}
public static Shape getLine(int shape, Point2D point1, Point2D point2)
{
return new Line2D.Double(point1, point2);
}
public static Shape getLine(int shape, double x1, double y1, double x2, double y2)
{
if(shape == LINE)
{
return new Line2D.Double(x1, y1, x2, y2);
}
return new Line2D.Double(x1, y1, x2, y2);
}
/**
* 绘制线的画笔
* @param width 线的宽度 ChartShape.LINE_NORMAL
* @return
*/
public static Stroke getLineStoke(float width, boolean isDash)
{
if(width < 0)
{
width = 0.0f;
}
if(isDash)
{
return new BasicStroke(width, 1, 1, 1.0f, new float[]{0.5f,3.0f},0.0f);
}
else
{
return new BasicStroke(width, 1, 1, 1.0f);
}
}
}
/** Chart 核心处理类*/
public class ChartProcessor extends BaseChart
{
@SuppressWarnings("unused")
private HttpServletRequest req;
private HttpServletResponse rep;
//背景字列表
private List<XYTextAnnotation> annoList;
public static String AXIS_LEFT = "axis_left"; //左轴;
private Map<String, NumberAxis> axisMap = new HashMap <String, NumberAxis>(); //轴映射
private Map<String, Map<String, ChartBean>> axis_data_map = new HashMap <String, Map<String, ChartBean>>(); //每条轴的数据集
private Map<String, XYLineAndShapeRenderer> axit_render_map = new HashMap <String, XYLineAndShapeRenderer>(); //每条轴和renderer的映射
private Map<String, Integer> axis_series_index_map = new HashMap <String, Integer>();//每条轴上的线索引映射
//背景颜色
private Color bgColor;
//水平底线的颜色
private Color bgHorizontalColor;
//竖直底线颜色
private Color bgVerticalColor;
private NumberAxis domainAxis;
public ChartProcessor(HttpServletResponse rep)
{
this(null, rep);
}
public ChartProcessor(HttpServletRequest req, HttpServletResponse rep)
{
this.req = req;
this.rep = rep;
annoList = new ArrayList<XYTextAnnotation>();
//初始化轴
axisMap.put(ChartProcessor.AXIS_LEFT, new NumberAxis());
//每条轴的数据集对象初始化
axis_data_map.put(ChartProcessor.AXIS_LEFT,
new HashMap<String, ChartBean>());
//每条轴的renderer初始化
axit_render_map.put(ChartProcessor.AXIS_LEFT,
new XYLineAndShapeRenderer());
//每条轴上的曲线索引初始化
axis_series_index_map.put(ChartProcessor.AXIS_LEFT, new Integer(0));
}
/**
* 画图方法
* @param title
* 图片的标题(图片的描述)
* @param xDesc
* x 轴的描述
* @param ylDesc
* 左y轴的描述
* @param yrDesc
* 右Y轴的描述
* @param showLineDesc
* 是否显示每条线的描述(即每条曲线的含义,在x轴下面列出每条线的含义)
* @param width
* 输出图片的宽度
* @param height
* 输出图片的高度
* @throws Exception
*/
public String createChart(String title, String xDesc, String ylDesc,
String ylsDesc, String yrDesc, boolean showLineDesc, int width,
int height) throws Exception
{
String chartPath = null;
if (rep == null)
{
throw new Exception("response 为空! 请先设置 response! ");
}
JFreeChart chart = ChartFactory.createXYLineChart(title, xDesc, ylDesc,createDataset(ChartProcessor.AXIS_LEFT),PlotOrientation.VERTICAL, showLineDesc, true, false);
//添加子标题
this.addTitle(chart);
XYPlot plot = chart.getXYPlot();
chart.setTextAntiAlias(false);
//设置背景图片
this.setBgImg(plot);
//添加背景字
for (XYTextAnnotation anno : annoList)
{
plot.addAnnotation(anno);
}
GradientPaint bg = new GradientPaint(0, 1000, Color.white, 0, 800,Color.white); //设置背景色
plot.setBackgroundPaint(bg);
plot.setRangeGridlinePaint(bgHorizontalColor);
plot.setDomainGridlinePaint(bgVerticalColor);
/**
* 设置各条轴
*/
if (axisMap.get(ChartProcessor.AXIS_LEFT) != null
&& axis_data_map.get(ChartProcessor.AXIS_LEFT) != null
&& !axis_data_map.get(ChartProcessor.AXIS_LEFT).isEmpty())
{
NumberAxis axisLeft = axisMap.get(ChartProcessor.AXIS_LEFT);
axisLeft.setLabel(ylDesc);
plot.setRangeAxis(0, axisLeft);
plot.setRenderer(0, axit_render_map.get(ChartProcessor.AXIS_LEFT));
}
if (domainAxis != null)
{
domainAxis.setLabel(xDesc);
domainAxis.setAutoRangeIncludesZero(false);
domainAxis.setLowerMargin(0);
plot.setDomainAxis(domainAxis);
}
Shape shape = new Rectangle(20, 10);
ChartEntity entity = new ChartEntity(shape);
StandardEntityCollection coll = new StandardEntityCollection();
coll.add(entity);
ChartRenderingInfo info = new ChartRenderingInfo(coll);
chartPath = ServletUtilities.saveChartAsJPEG(chart, width, height,info, req.getSession());
axis_data_map.get(ChartProcessor.AXIS_LEFT).clear();
return chartPath;
}
/**
* 设置某条轴想要显示的数据<br>
* @param axisName
* 轴的名称
* @param lineName
* 线的名称
* @param x
* 横坐标
* @param y
* 纵坐标
* @return 数据是否加入成功
*/
public boolean addData(String axisName, String lineName, Number x, Number y)
{
if (lineName == null || "".equals(lineName.trim()) || x == null
|| y == null)
return false;
if (axisName == null || axisMap.get(axisName) == null)
return false;
if (axis_data_map.get(axisName) != null)
{
Map<String, ChartBean> map = axis_data_map.get(axisName);
if (map.containsKey(lineName))
{
ChartBean seriesbean = map.get(lineName);
if (seriesbean.getSeries() != null)
seriesbean.getSeries().add(x, y);
}
else
{
XYSeries series = new XYSeries(lineName);
series.add(x, y);
ChartBean bean = new ChartBean();
bean.setSeries(series);
map.put(lineName, bean);
}
}
return true;
}
/**
* 设置某条轴曲线是否显示各个坐标点( 平滑曲线或者标明坐标点的曲线,设置某条轴上的所有线的点)
* @param lineShapeVisible(true:显示
* false:不显示)
*/
public void setLineShapeVisible(String axisName, boolean lineShapeVisible)
{
if (axisName != null && !"".equals(axisName.trim()))
{
if (axit_render_map.get(axisName) != null)
{
axit_render_map.get(axisName).setBaseShapesVisible(
lineShapeVisible);
}
}
}
/**
* 设置某条轴具体某条曲线是否显示各个坐标点
* @param axisName
* 轴名称
* @param lineName
* 曲线名
* @param flag
*/
public void setLineShapeVisible(String axisName, String lineName,
boolean flag)
{
if (lineName == null)
return;
if (axis_data_map.get(axisName) != null)
{
Map<String, ChartBean> map = axis_data_map.get(axisName);
if (map.containsKey(lineName))
{
ChartBean bean = map.get(lineName);
bean.setShapeVisible(flag);
}
else
{
ChartBean bean = new ChartBean();
bean.setShapeVisible(flag);
map.put(lineName, bean);
}
}
}
/**
* 设置某条轴具体某条曲线是否是虚线
* @param lineName
* 曲线名
* @param flag
*/
public void setLineDash(String axisName, String lineName, boolean flag)
{
if (lineName == null)
return;
if (axisName == null || axisMap.get(axisName) == null)
return;
if (axis_data_map.get(axisName) != null)
{
Map<String, ChartBean> map = axis_data_map.get(axisName);
if (map.containsKey(lineName))
{
ChartBean bean = map.get(lineName);
bean.setLineDash(flag);
}
else
{
ChartBean bean = new ChartBean();
bean.setLineDash(flag);
map.put(lineName, bean);
}
}
}
/**
* 设置某条轴具体某条曲线是否显示线条本身
* @param lineName
* 曲线名
* @param flag
*/
public void setLineVisible(String axisName, String lineName, boolean flag)
{
if (lineName == null)
return;
if (axisName == null || axisMap.get(axisName) == null)
return;
if (axis_data_map.get(axisName) != null)
{
Map<String, ChartBean> map = axis_data_map.get(axisName);
if (map.containsKey(lineName))
{
ChartBean bean = map.get(lineName);
bean.setLineVisible(flag);
}
else
{
ChartBean bean = new ChartBean();
bean.setLineVisible(flag);
map.put(lineName, bean);
}
}
}
/**
* 设置背景颜色
* @param color
*/
public void setBackgroundColor(Color color)
{
if (color != null)
this.bgColor = color;
}
/**
* 设置水平底线的颜色
* @param color
*/
public void setBgHorizontalLineColor(Color color)
{
if (color != null)
{
this.bgHorizontalColor = color;
}
}
/**
* 设置竖直底线的颜色
* @param color
*/
public void setBgVerticalLineColor(Color color)
{
if (color != null)
{
this.bgVerticalColor = color;
}
}
/**
* 设置某条轴各曲线的颜色
* @param lineName
* 要设置颜色的线的名称
* @param color
* 线的颜色
*/
public void setLineColor(String axisName, String lineName, Color color)
{
if (lineName == null)
return;
if (axisName == null || axisMap.get(axisName) == null)
return;
if (axis_data_map.get(axisName) != null)
{
Map<String, ChartBean> map = axis_data_map.get(axisName);
if (map.containsKey(lineName))
{
ChartBean bean = map.get(lineName);
bean.setLineColor(color);
}
else
{
ChartBean bean = new ChartBean();
bean.setLineColor(color);
map.put(lineName, bean);
}
}
}
/**
* 设置某条轴各曲线的点的形状
* @param lineName
* 要设置的线的名称
* @param shape
* 形状
*/
public void setLineShape(String axisName, String lineName, Shape shape)
{
if (lineName == null)
return;
if (axisName == null || axisMap.get(axisName) == null)
return;
if (axis_data_map.get(axisName) != null)
{
Map<String, ChartBean> map = axis_data_map.get(axisName);
if (!map.containsKey(lineName))
{
ChartBean bean = new ChartBean();
bean.setShape(shape);
map.put(lineName, bean);
}
else
{
ChartBean bean = map.get(lineName);
bean.setShape(shape);
}
}
}
/**
* 设置某条轴各曲线的宽度
* @param lineName
* 要设置的线的名称
* @param width
* 宽度
*/
public void setLineWidth(String axisName, String lineName, float width)
{
if (lineName == null)
return;
if (axisName == null || axisMap.get(axisName) == null)
return;
if (axis_data_map.get(axisName) != null)
{
Map<String, ChartBean> map = axis_data_map.get(axisName);
if (!map.containsKey(lineName))
{
ChartBean bean = new ChartBean();
bean.setLineWidth(width);
}
else
{
ChartBean bean = map.get(lineName);
bean.setLineWidth(width);
}
}
}
/**
* 设置某条轴各曲线的点的填充颜色
* @param lineName
* 要设置的线的名称
* @param color
* 颜色
*/
public void setLineShapeFilledColor(String axisName, String lineName, Color color)
{
if(lineName == null)
return ;
if(axisName == null || axisMap.get(axisName) == null)
return ;
if(axis_data_map.get(axisName)!= null)
{
Map<String, ChartBean> map = axis_data_map.get(axisName);
if(!map.containsKey(lineName))
{
ChartBean bean = new ChartBean();
bean.setShapeFilled(true);
bean.setShapeColor(color);
map.put(lineName, bean);
}
else
{
ChartBean bean = map.get(lineName);
bean.setShapeFilled(true);
bean.setShapeColor(color);
}
}
}
/**
* 设置某条Y轴的间隔
*
* <pre>
* 如果想设置左Y轴的两个刻度之间间隔为10 则setYUnit(MulAxisLineChart.AXIS_LEFT,10)
* </pre>
*
* @param unit
*/
public void setYUnit(String axisName, double unit)
{
if (axisName == null || axisMap.get(axisName) == null)
return;
NumberTickUnit tickUnit = new NumberTickUnit(unit);
axisMap.get(axisName).setAutoTickUnitSelection(false);
axisMap.get(axisName).setTickUnit(tickUnit);
}
/**
* 设置X轴的范围
*
* <pre>
* 如果想设置X轴的范围为0-30 则setXRange(0,30)
* </pre>
*/
public void setXRange(double lower, double upper)
{
if (domainAxis == null)
domainAxis = new NumberAxis();
domainAxis.setRange(lower, upper);
}
/**
* 设置Y轴的范围
*
* <pre>
* 如果想设置左Y轴的范围为0-30 则setYRangeLeft(MulAxisLineChart.AXIS_LEFT,0,30)
* </pre>
*/
public void setYRange(String axisName, double lower, double upper)
{
if (axisName == null || axisMap.get(axisName) == null)
return;
axisMap.get(axisName).setRange(lower, upper);
}
/**
* 设置X轴的间隔
*
* <pre>
* 如果想设置X轴的两个刻度之间间隔为10 则setXUnit(10)
* </pre>
*
* @param unit
*/
public void setXUnit(double unit)
{
if (domainAxis == null)
{
domainAxis = new NumberAxis();
}
NumberTickUnit tickUnit = new NumberTickUnit(unit);
domainAxis.setAutoTickUnitSelection(false);
domainAxis.setTickUnit(tickUnit);
}
/**
* 设置X轴是否可见
* @param flag
*/
public void setXVisible(boolean flag)
{
if (domainAxis == null)
{
domainAxis = new NumberAxis();
}
domainAxis.setVisible(flag);
}
/**
* 设置某条Y轴是否可见
* @param flag
*/
public void setYVisible(String axisName, boolean flag)
{
if (axisName == null || axisMap.get(axisName) == null)
return;
axisMap.get(axisName).setVisible(flag);
}
/**
* 设置X轴是否从零开始
* @param flag
* true:是 false:否
*/
public void setXStartWithZero(boolean flag)
{
if (domainAxis == null)
{
domainAxis = new NumberAxis();
}
domainAxis.setAutoRangeIncludesZero(flag);
}
/**
* 设置某条Y轴是否从零开始
* @param flag
* true:是 false:否
*/
public void setYStartWithZero(String axisName, boolean flag)
{
if (axisName == null || axisMap.get(axisName) == null)
return;
axisMap.get(axisName).setAutoRangeIncludesZero(flag);
}
/**
* 设置图片的背景字
* @param value
* 要显示的字
* @param x
* 要显示的字在整个图片中的横坐标
* @param y
* 要显示的字在整个图片中的纵坐标
*/
public void addBackgroundValue(String value, double x, double y)
{
Font font = new Font("隶书", Font.PLAIN, 15);
this.addBackgroundValue(value, x, y, font);
}
/**
* 设置图片的背景字
* @param value
* 要显示的字
* @param x
* 要显示的字在整个图片中的横坐标
* @param y
* 要显示的字在整个图片中的纵坐标
* @param font
* 要显示字的样式
*/
public void addBackgroundValue(String value, double x, double y, Font font)
{
if (value == null)
value = new String("");
if (font == null)
{
font = new Font("隶书", Font.PLAIN, 15);
}
addBackgroundValue(value, x, y, font, null);
}
public void addBackgroundValue(String value, double x, double y, Font font,
Color color)
{
if (value == null)
value = new String("");
XYTextAnnotation anno = new XYTextAnnotation(value, x, y);
if (font == null)
{
font = new Font("隶书", Font.PLAIN, 15);
}
if (color == null)
color = Color.black;
anno.setFont(font);
anno.setTextAnchor(TextAnchor.BASELINE_CENTER);
anno.setPaint(color);
annoList.add(anno);
}
/**
* 下面两个方法是构造左右轴数据集 构造完成后调动左右轴各条曲线初始化方法
* @return
*/
private XYSeriesCollection createDataset(String axisName)
{
if (axisName == null)
return null;
XYSeriesCollection collection = new XYSeriesCollection();
if (axis_data_map.get(axisName) != null
&& !axis_data_map.get(axisName).isEmpty())
{
if (axis_data_map.get(axisName) == null)
return null;
Integer index = axis_series_index_map.get(axisName);
for (ChartBean bean : axis_data_map.get(axisName).values())
{
if (bean.getSeries() == null)
continue;
collection.addSeries(bean.getSeries());
if (index != null)
{
bean.setIndex(index);
index++;
}
}
initSeries(axisName);
}
return collection;
}
/**
* 下面几个方法是设置左右轴的初始数据 要在构造完数据集过后 知道每条曲线的索引才可以设置
*/
private void initSeries(String axisName)
{
if (axisName == null)
return;
if (axis_data_map.get(axisName) != null
&& !axis_data_map.get(axisName).isEmpty())
{
XYLineAndShapeRenderer renderer = axit_render_map.get(axisName);
for (ChartBean bean : axis_data_map.get(axisName).values())
{
renderer.setSeriesStroke(bean.getIndex(), bean.getLineStroke()); //线的笔触
renderer.setUseFillPaint(true);
if (bean.getLineColor() != null) //线的颜色
{
renderer.setSeriesPaint(bean.getIndex(), bean
.getLineColor());
}
if (bean.getShapeVisible() != null) //点是否可见
{
renderer.setSeriesShapesVisible(bean.getIndex(), bean
.getShapeVisible());
}
if (bean.getLineVisible() != null)
{
renderer.setSeriesLinesVisible(bean.getIndex(), bean
.getLineVisible()); //线是否可见
}
if (bean.getShape() != null)
{
renderer.setSeriesShape(bean.getIndex(), bean.getShape()); //设置点的形状
}
if (bean.getShapeFilled() && bean.getShapeColor() != null) //设置对点的具体填充色
{
renderer.setSeriesFillPaint(bean.getIndex(), bean
.getShapeColor());
}
else if (!bean.getShapeFilled() && renderer.getUseFillPaint()) //没有设置对点的具体填充色,则默认用线的颜色填充
{
renderer.setSeriesFillPaint(bean.getIndex(), bean
.getLineColor());
}
}
}
}
@Override
protected void addTitle(JFreeChart chart)
{
if (textTitleList != null)
{
for (TextTitle tt : textTitleList)
{
chart.addSubtitle(tt);
}
}
}
@Override
protected void setBgImg(Plot plot)
{
if (bgImg != null)
plot.setBackgroundImage(bgImg);
}
}
/**体温单实现类 */
public class TwdChartService
{
private int top_length = 3; //顶端的高度
private int top_rows=10; //顶部的行数
private double top_row_height=top_length/(double)top_rows; //顶部每行的高度
private int bottom_length =3; //底部的高度
private int bottom_rows=10 ;//底部的行数
private double bottom_row_height=bottom_length/(double)bottom_rows ; //底部每行的高度
private int grid_left = 6; //左Y轴格子数
private int grid_right =0; //右Y轴格子数
private int x_unit = 6; //多少个小格子组成一个大格子
private double grid_row_height = 0.2; //数据区每个格子的高度
private double grid_col_width=1.0;
private int y_grid_length=8; //y轴所有格子的长度
private int x_grid_length=42; //x轴所有格子的长度
private int grid_rows=(int)Math.round(y_grid_length/grid_row_height); //中间格子的行数
private int start_temperature=34; //起始的体温 从底部高度开始算起
private int start_pulse=20; //起始的脉搏 从底部高度开始算起
private int x_length = grid_left+x_grid_length+grid_right; //x轴的长度
private int y_length = top_length+y_grid_length+bottom_length; //y轴的长度
Font font = new Font("SansSerif", Font.PLAIN, 12);
private double round_size = 8d;
public void initAllData(ChartProcessor chart,Map map)
{
initTopChart(chart, map);
initGridChart(chart);
initBottomChart(chart, map);
initGridDynamicData(chart, map);
initChart(chart);
}
/**
* 初始化坐标轴、边框
* @param chart
*/
private void initChart(ChartProcessor chart)
{
//初始化各坐标轴
chart.setXRange(0, x_length);
chart.setXUnit(1);
chart.setXVisible(false);
chart.setBgHorizontalLineColor(Color.white);
chart.setBgVerticalLineColor(Color.white);
chart.setYUnit(ChartProcessor.AXIS_LEFT, 1);
chart.setYRange(ChartProcessor.AXIS_LEFT, 0, y_length);
chart.addData(ChartProcessor.AXIS_LEFT, "basic_left", 0,y_length);
chart.setLineVisible(ChartProcessor.AXIS_LEFT, "basic_left", false);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT, "basic_left",false);
chart.setYVisible(ChartProcessor.AXIS_LEFT, false);
//四条边框
//上
chart.addData(ChartProcessor.AXIS_LEFT, "basic_frame_line_top", 0,y_length);
chart.addData(ChartProcessor.AXIS_LEFT, "basic_frame_line_top",x_length, y_length);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,"basic_frame_line_top", false);
chart.setLineColor(ChartProcessor.AXIS_LEFT, "basic_frame_line_top",Color.BLACK);
chart.setLineWidth(ChartProcessor.AXIS_LEFT, "basic_frame_line_top",ChartShape.LINE_WIDE);
//住院天数
chart.addData(ChartProcessor.AXIS_LEFT, "basic_line_top", 0,bottom_length+y_grid_length+top_row_height*5);
chart.addData(ChartProcessor.AXIS_LEFT, "basic_line_top",x_length,bottom_length+y_grid_length+top_row_height*5);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,"basic_line_top", false);
chart.setLineColor(ChartProcessor.AXIS_LEFT, "basic_line_top",Color.BLACK);
chart.setLineWidth(ChartProcessor.AXIS_LEFT, "basic_line_top",ChartShape.LINE_NORMAL);
//下
chart.addData(ChartProcessor.AXIS_LEFT, "basic_frame_line_bottom", 0,0.01);
chart.addData(ChartProcessor.AXIS_LEFT, "basic_frame_line_bottom",x_length, 0.01);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,"basic_frame_line_bottom", false);
chart.setLineColor(ChartProcessor.AXIS_LEFT,"basic_frame_line_bottom", Color.BLACK);
chart.setLineWidth(ChartProcessor.AXIS_LEFT,"basic_frame_line_bottom", ChartShape.LINE_NORMAL);
//左
chart.addData(ChartProcessor.AXIS_LEFT, "basic_y_line", 0, 0);
chart.addData(ChartProcessor.AXIS_LEFT, "basic_y_line", 0,y_length);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT, "basic_y_line",false);
chart.setLineColor(ChartProcessor.AXIS_LEFT, "basic_y_line",Color.BLACK);
chart.setLineWidth(ChartProcessor.AXIS_LEFT, "basic_y_line",ChartShape.LINE_WIDE);
//左2
chart.addData(ChartProcessor.AXIS_LEFT, "basic_y_line_sec",grid_left, 0);
chart.addData(ChartProcessor.AXIS_LEFT, "basic_y_line_sec",grid_left, y_length-top_row_height *5);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,"basic_y_line_sec", false);
chart.setLineColor(ChartProcessor.AXIS_LEFT, "basic_y_line_sec",Color.BLACK);
chart.setLineWidth(ChartProcessor.AXIS_LEFT, "basic_y_line_sec",ChartShape.LINE_NORMAL);
//右
chart.addData(ChartProcessor.AXIS_LEFT, "basic_y_line_right2",x_length-0.0005 ,0);
chart.addData(ChartProcessor.AXIS_LEFT, "basic_y_line_right2",x_length-0.0005, y_length);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,"basic_y_line_right2", false);
chart.setLineColor(ChartProcessor.AXIS_LEFT, "basic_y_line_right2",Color.BLACK);
chart.setLineWidth(ChartProcessor.AXIS_LEFT, "basic_y_line_right2",ChartShape.LINE_NORMAL);
//呼吸
chart.addData(ChartProcessor.AXIS_LEFT, "bottom_horizatal_line", 0,bottom_length);
chart.addData(ChartProcessor.AXIS_LEFT, "bottom_horizatal_line",x_length-grid_right, bottom_length);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,"bottom_horizatal_line", false);
chart.setLineColor(ChartProcessor.AXIS_LEFT, "bottom_horizatal_line",Color.BLACK);
chart.setLineWidth(ChartProcessor.AXIS_LEFT, "bottom_horizatal_line",ChartShape.LINE_NORMAL);
//时间边框
chart.addData(ChartProcessor.AXIS_LEFT, "top_horizatal_line", 0,y_length - top_length);
chart.addData(ChartProcessor.AXIS_LEFT, "top_horizatal_line",x_length-grid_right, y_length - top_length);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,"top_horizatal_line", false);
chart.setLineColor(ChartProcessor.AXIS_LEFT, "top_horizatal_line",Color.BLACK);
chart.setLineWidth(ChartProcessor.AXIS_LEFT, "top_horizatal_line",ChartShape.LINE_NORMAL);
//初始化脉搏、体温坐标轴
for (int i = 0; i<y_grid_length; i++)
{
Font font = new Font("SansSerif", Font.PLAIN, 12);
String value_left = (start_temperature + i+1 ) + "";
String value_left_sec = (start_pulse + (i+1)* 20) + "";
double y =bottom_length+ i + 0.8;
chart.addBackgroundValue(value_left, grid_left / 6 * 5, y, font);
chart.addBackgroundValue(value_left_sec, grid_left / 4 + 0.05, y,font, Color.RED);
}
//时间 至 顶部 添加纵线 呼吸 至 底部 添加纵线
//纵向格子
for (int i = 0; i <= x_grid_length; i++)
{
float chartShape = ChartShape.LINE_THIN;
double temp_top_height=y_length - top_length+top_row_height*2;
double temp_bottom_height=bottom_length-bottom_row_height*2;
if (i % 6 == 0)
{
chartShape = ChartShape.LINE_WIDE;
temp_top_height=y_length - top_length+top_row_height*5;
temp_bottom_height=0;
}
String line_name = "line_time2top_vertical_sec_" + i;
chart.addData(ChartProcessor.AXIS_LEFT, line_name, grid_left + i,y_length-top_length);
chart.addData(ChartProcessor.AXIS_LEFT, line_name, grid_left + i,temp_top_height);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT, line_name,false);
chart.setLineColor(ChartProcessor.AXIS_LEFT, line_name,Color.BLACK);
chart.setLineWidth(ChartProcessor.AXIS_LEFT, line_name, chartShape);
String line_name1 = "line_breather2bottom_vertical_sec_" + i;
chart.addData(ChartProcessor.AXIS_LEFT, line_name1, grid_left + i,bottom_length);
chart.addData(ChartProcessor.AXIS_LEFT, line_name1, grid_left + i,temp_bottom_height);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT, line_name1,false);
chart.setLineColor(ChartProcessor.AXIS_LEFT, line_name1,Color.BLACK);
chart.setLineWidth(ChartProcessor.AXIS_LEFT, line_name1, chartShape);
}
}
/*****
*顶部标题初始化
*/
private void initTopChart(ChartProcessor chart,Map map)
{
chart.addBackgroundValue("姓 名:", grid_left /3, bottom_length+y_grid_length+top_row_height*5 + 0.1, font);
chart.addBackgroundValue(map.get("patientname")+"", grid_left / 2+x_unit/2, bottom_length+y_grid_length+top_row_height*5 + 0.1, font);
chart.addBackgroundValue("入 院 日 期:", grid_left / 2+x_unit/3+x_unit, bottom_length+y_grid_length+top_row_height*5 + 0.1, font);
chart.addBackgroundValue(map.get("indate")+"", grid_left / 2+x_unit*2, bottom_length+y_grid_length+top_row_height*5 + 0.1, font);
chart.addBackgroundValue("科 室:", grid_left / 2+x_unit*3, bottom_length+y_grid_length+top_row_height*5 + 0.1, font);
chart.addBackgroundValue(map.get("sectionAreaName")+"", grid_left / 2+x_unit*3+x_unit, bottom_length+y_grid_length+top_row_height*5 + 0.1, font);
chart.addBackgroundValue("床 号:", x_length-x_unit*2-3, bottom_length+y_grid_length+top_row_height*5 + 0.1, font);
chart.addBackgroundValue(map.get("badNo")+"",x_length-x_unit*2, bottom_length+y_grid_length+top_row_height*5 + 0.1, font);
chart.addBackgroundValue("住 院 号:", x_length-x_unit-2, bottom_length+y_grid_length+top_row_height*5 + 0.1, font);
chart.addBackgroundValue(map.get("hisno")+"", x_length-x_unit/2-2, bottom_length+y_grid_length+top_row_height*5 + 0.1, font);
chart.addBackgroundValue("体 温 单", x_length/2, bottom_length+y_grid_length+top_row_height*6+0.2, new Font("SansSerif", Font.PLAIN, 15));
chart.addBackgroundValue("九 江 市 妇 幼 保 健 院", x_length/2, bottom_length+y_grid_length+top_row_height*8 + 0.1, new Font("SansSerif", Font.PLAIN, 20));
/*****
* 顶部数据初始化
**/
chart.addBackgroundValue("住 院 天 数", grid_left / 2,bottom_length+y_grid_length+top_row_height*4 + 0.1, font);
chart.addData(ChartProcessor.AXIS_LEFT, "basic_line_time_date", 0,bottom_length+y_grid_length+top_row_height*4);
chart.addData(ChartProcessor.AXIS_LEFT, "basic_line_time_date",x_length-grid_right, bottom_length+y_grid_length+top_row_height*4);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,"basic_line_time_date", false);
chart.setLineColor(ChartProcessor.AXIS_LEFT, "basic_line_time_date",Color.BLACK);
chart.setLineWidth(ChartProcessor.AXIS_LEFT, "basic_line_time_date",ChartShape.LINE_THIN);
chart.addBackgroundValue("手 术 后 天 数", grid_left / 2, bottom_length+y_grid_length+top_row_height*3 + 0.1, font);
chart.addData(ChartProcessor.AXIS_LEFT, "basic_line_time_in_day", 0,bottom_length+y_grid_length+top_row_height*3);
chart.addData(ChartProcessor.AXIS_LEFT, "basic_line_time_in_day",x_length-grid_right, bottom_length+y_grid_length+top_row_height*3);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,"basic_line_time_in_day", false);
chart.setLineColor(ChartProcessor.AXIS_LEFT,"basic_line_time_in_day", Color.BLACK);
chart.setLineWidth(ChartProcessor.AXIS_LEFT,"basic_line_time_in_day", ChartShape.LINE_THIN);
chart.addBackgroundValue("日 期", grid_left / 2, bottom_length+y_grid_length+top_row_height*2+0.1, font);
chart.addData(ChartProcessor.AXIS_LEFT, "basic_line_time_ops_day", 0,bottom_length+y_grid_length+top_row_height*2);
chart.addData(ChartProcessor.AXIS_LEFT, "basic_line_time_ops_day",x_length-grid_right, bottom_length+y_grid_length+top_row_height*2);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,"basic_line_time_ops_day", false);
chart.setLineColor(ChartProcessor.AXIS_LEFT,"basic_line_time_ops_day", Color.BLACK);
chart.setLineWidth(ChartProcessor.AXIS_LEFT,"basic_line_time_ops_day", ChartShape.LINE_THIN);
chart.addBackgroundValue("时 间", grid_left / 2, bottom_length+y_grid_length+top_row_height*1+0.1, font);
chart.addData(ChartProcessor.AXIS_LEFT, "basic_line_time_op_day", 0,bottom_length+y_grid_length+top_row_height*1);
chart.addData(ChartProcessor.AXIS_LEFT, "basic_line_time_op_day",x_length-grid_right,bottom_length+y_grid_length+top_row_height*1);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,"basic_line_time_op_day", false);
chart.setLineColor(ChartProcessor.AXIS_LEFT,"basic_line_time_op_day", Color.BLACK);
chart.setLineWidth(ChartProcessor.AXIS_LEFT,"basic_line_time_op_day", ChartShape.LINE_THIN);
//时间节点2 ,6,10,14,18,22
for(int i=0;i<x_grid_length;i++)
{
Integer []hours=TwdConstant.HOURS; //时间段
int beginHour = hours[i<x_unit?i:i%x_unit];
Color hourColor = null;
if (beginHour == 2 || beginHour == 6 || beginHour == 22)
hourColor = Color.RED;
else
hourColor = Color.BLACK;
chart.addBackgroundValue(beginHour + "", grid_left + i + 0.5,bottom_length+y_grid_length+0.1, font, hourColor);
}
chart.addBackgroundValue("体温", grid_left / 6 * 5, bottom_length+y_grid_length+0.1, font, Color.BLACK);
chart.addBackgroundValue("脉搏", grid_left / 4 + 0.2,bottom_length+y_grid_length+0.1 , font, Color.BLACK);
/**
* 体温和脉搏之间的纵轴
*/
chart.addData(ChartProcessor.AXIS_LEFT,"vertical_line_between_temp_pulse", grid_left / 2,bottom_length);
chart.addData(ChartProcessor.AXIS_LEFT,"vertical_line_between_temp_pulse", grid_left / 2,bottom_length+y_grid_length+top_row_height);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,"vertical_line_between_temp_pulse", false);
chart.setLineColor(ChartProcessor.AXIS_LEFT,"vertical_line_between_temp_pulse", Color.BLACK);
chart.setLineWidth(ChartProcessor.AXIS_LEFT,"vertical_line_between_temp_pulse", ChartShape.LINE_THIN);
/******************************
* 顶部动态数据展示
* ****************************
*/
/**
* 日期信息显示 例子:2012-07-31、08-01、02、03、04、05
*/
List<String> twdDateList=(List<String>)map.get("twdDateList");
List<String> dateList=(List<String>)map.get("dateList"); //日期集合
if(twdDateList!=null&&twdDateList.size()>0)
{
for(int i=0;i<twdDateList.size();i++)
{
chart.addBackgroundValue(twdDateList.get(i),grid_left*(i+1)+ x_unit / 2,bottom_length+y_grid_length+top_row_height*2+ 0.1, font); //日期
}
}
if(dateList!=null&&dateList.size()>0)
{
List<Operation> operationList=(List<Operation>)map.get("operationList"); //手术信息集合,按照手术日期降序存储
for(int i=0;i<dateList.size();i++)
{
Date tempDate= DateUtil.parseDate(dateList.get(i).toString());
long diffDays=DateUtil.getDateDiff(tempDate,DateUtil.parseDate(map.get("indate").toString()));
//住院日数
chart.addBackgroundValue(diffDays+"",grid_left*(i+1)+ x_unit / 2,bottom_length+y_grid_length+top_row_height*4+0.1, font);
//手术后天数
int firstOperationDay=0; //第一次手术天数
int secondOperationDay=0; //第二次手术天数
if(operationList!=null&&operationList.size()>0)
{
for(int j=0;j<operationList.size();j++)
{
if(operationList.get(j).getOperationdate()!=null)
{
int tempDiffDays=(int)DateUtil.getDateDiff(tempDate, operationList.get(j).getOperationdate());
if(tempDiffDays>0&&tempDiffDays<=14)
{
secondOperationDay=tempDiffDays;
if(j+1>=operationList.size())
{
break;
}
int tempDiffDays1=(int)DateUtil.getDateDiff(operationList.get(j).getOperationdate(), operationList.get(j+1).getOperationdate());
if(tempDiffDays1>0&&tempDiffDays1<=14&&operationList.get(j+1).getOperationdate()!=null)
firstOperationDay=(int)DateUtil.getDateDiff(tempDate, operationList.get(j+1).getOperationdate());;
break;
}
}
}
}
if(firstOperationDay>0)
{
chart.addBackgroundValue(secondOperationDay+"/"+firstOperationDay,grid_left*(i+1)+ x_unit / 2,bottom_length+y_grid_length+top_row_height*3+0.1, font);
}
else if(secondOperationDay>0)
{
chart.addBackgroundValue(secondOperationDay+"",grid_left*(i+1)+ x_unit / 2,bottom_length+y_grid_length+top_row_height*3+0.1, font);
}
}
}
}
/***
* 中间格子初始化
*/
private void initGridChart(ChartProcessor chart)
{
//纵向格子
for (int i = 0; i <=x_grid_length; i++)
{
float chartShape = ChartShape.LINE_THIN;
if (i % 6 == 0)
{
chartShape = ChartShape.LINE_WIDE;
}
String line_name = "basic_line_ruliang_vertical_sec_" + i;
chart.addData(ChartProcessor.AXIS_LEFT, line_name, grid_left + i,bottom_length);
chart.addData(ChartProcessor.AXIS_LEFT, line_name, grid_left + i,y_length - top_length);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT, line_name,false);
chart.setLineColor(ChartProcessor.AXIS_LEFT, line_name,Color.BLACK);
chart.setLineWidth(ChartProcessor.AXIS_LEFT, line_name, chartShape);
}
//横向格子
for (int i = 0; i < grid_rows; i++)
{
String line_name="grid_horizontal_line"+i;
float horizontalShape=ChartShape.LINE_THIN;
Color horizontalColor=Color.BLACK;
if(i%5==0)
{
horizontalShape=ChartShape.LINE_WIDE;
}
if(i==15) //37度对应线为红色
{
horizontalColor=Color.RED;
}
chart.addData(ChartProcessor.AXIS_LEFT,line_name,grid_left,bottom_length+grid_row_height*i);
chart.addData(ChartProcessor.AXIS_LEFT,line_name ,x_length-grid_right,bottom_length+grid_row_height*i);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,line_name, false);
chart.setLineColor(ChartProcessor.AXIS_LEFT, line_name,horizontalColor);
chart.setLineWidth(ChartProcessor.AXIS_LEFT,line_name,horizontalShape);
}
}
/**
* 底部数据初始化
*/
public void initBottomChart(ChartProcessor chart,Map map)
{
//底部数据初始化
chart.addBackgroundValue("呼 吸 (次/分)", grid_left / 2, bottom_length- bottom_row_height, font);
chart.addData(ChartProcessor.AXIS_LEFT, "basic_line_huxi", 0,bottom_length - bottom_row_height*2);
chart.addData(ChartProcessor.AXIS_LEFT, "basic_line_huxi", x_length-grid_right,bottom_length - bottom_row_height*2);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,"basic_line_huxi", false);
chart.setLineColor(ChartProcessor.AXIS_LEFT, "basic_line_huxi",Color.BLACK);
chart.setLineWidth(ChartProcessor.AXIS_LEFT, "basic_line_huxi",ChartShape.LINE_THIN);
chart.addBackgroundValue(" 尿 量 ml", grid_left / 2, bottom_length- bottom_row_height * 3 + 0.1, font);
chart.addData(ChartProcessor.AXIS_LEFT,"basic_line_bottom_niaoliang", 0, bottom_length- bottom_row_height * 3);
chart.addData(ChartProcessor.AXIS_LEFT,"basic_line_bottom_niaoliang", x_length-grid_right, bottom_length- bottom_row_height * 3);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,"basic_line_bottom_niaoliang", false);
chart.setLineColor(ChartProcessor.AXIS_LEFT,"basic_line_bottom_niaoliang", Color.BLACK);
chart.setLineWidth(ChartProcessor.AXIS_LEFT,"basic_line_bottom_niaoliang", ChartShape.LINE_THIN);
chart.addBackgroundValue("入 量 ml", grid_left / 2, bottom_length- bottom_row_height * 4 + 0.1, font);
chart.addData(ChartProcessor.AXIS_LEFT, "basic_line_bottom_ruliang",0, bottom_length - bottom_row_height * 4);
chart.addData(ChartProcessor.AXIS_LEFT, "basic_line_bottom_ruliang", x_length-grid_right, bottom_length - bottom_row_height * 4);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT, "basic_line_bottom_ruliang", false);
chart.setLineColor(ChartProcessor.AXIS_LEFT, "basic_line_bottom_ruliang", Color.BLACK);
chart.setLineWidth(ChartProcessor.AXIS_LEFT, "basic_line_bottom_ruliang", ChartShape.LINE_THIN);
chart.addBackgroundValue("出 量 ml", grid_left / 2, bottom_length- bottom_row_height * 5 + 0.1, font);
chart.addData(ChartProcessor.AXIS_LEFT, "basic_line_bottom_chuliang",0, bottom_length - bottom_row_height *5);
chart.addData(ChartProcessor.AXIS_LEFT, "basic_line_bottom_chuliang",x_length-grid_right, bottom_length - bottom_row_height * 5);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,"basic_line_bottom_chuliang", false);
chart.setLineColor(ChartProcessor.AXIS_LEFT,"basic_line_bottom_chuliang", Color.BLACK);
chart.setLineWidth(ChartProcessor.AXIS_LEFT,"basic_line_bottom_chuliang", ChartShape.LINE_THIN);
chart.addBackgroundValue(" 大 便 次 数 ", grid_left / 2, bottom_length- bottom_row_height * 6 + 0.1, font);
chart.addData(ChartProcessor.AXIS_LEFT,"basic_line_bottom_dabiancishu", 0, bottom_length- bottom_row_height *6);
chart.addData(ChartProcessor.AXIS_LEFT,"basic_line_bottom_dabiancishu", x_length-grid_right, bottom_length- bottom_row_height * 6);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,"basic_line_bottom_dabiancishu", false);
chart.setLineColor(ChartProcessor.AXIS_LEFT,"basic_line_bottom_dabiancishu", Color.BLACK);
chart.setLineWidth(ChartProcessor.AXIS_LEFT,"basic_line_bottom_dabiancishu", ChartShape.LINE_THIN);
chart.addBackgroundValue(" 血 压 mmHg", grid_left / 2, bottom_length- bottom_row_height * 7 + 0.1, font);
chart.addData(ChartProcessor.AXIS_LEFT, "basic_line_bottom_xueya", 0,bottom_length - bottom_row_height * 7);
chart.addData(ChartProcessor.AXIS_LEFT, "basic_line_bottom_xueya",x_length-grid_right, bottom_length - bottom_row_height * 7);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,"basic_line_bottom_xueya", false);
chart.setLineColor(ChartProcessor.AXIS_LEFT,"basic_line_bottom_xueya", Color.BLACK);
chart.setLineWidth(ChartProcessor.AXIS_LEFT,"basic_line_bottom_xueya", ChartShape.LINE_THIN);
for (int i = 0; i < 7; i++)
{
String line_name = "basic_line__bottom_xueya_vertical" + i;
chart.addData(ChartProcessor.AXIS_LEFT, line_name, grid_left+ x_unit / 2 + x_unit * (i), bottom_length- bottom_row_height * 6);
chart.addData(ChartProcessor.AXIS_LEFT, line_name, grid_left+ x_unit / 2 + x_unit * (i), bottom_length- bottom_row_height * 7);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT, line_name,false);
chart.setLineColor(ChartProcessor.AXIS_LEFT, line_name,Color.black);
chart.setLineWidth(ChartProcessor.AXIS_LEFT, line_name,ChartShape.LINE_THIN);
}
chart.addBackgroundValue("体 重 kg", grid_left / 2, bottom_length- bottom_row_height * 8 + 0.1, font);
chart.addData(ChartProcessor.AXIS_LEFT, "basic_line_bottom_tizhong",0, bottom_length - bottom_row_height *8);
chart.addData(ChartProcessor.AXIS_LEFT, "basic_line_bottom_tizhong",x_length-grid_right, bottom_length - bottom_row_height * 8);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,"basic_line_bottom_tizhong", false);
chart.setLineColor(ChartProcessor.AXIS_LEFT,"basic_line_bottom_tizhong", Color.BLACK);
chart.setLineWidth(ChartProcessor.AXIS_LEFT,"basic_line_bottom_tizhong", ChartShape.LINE_THIN);
chart.addBackgroundValue("身 高 cm", grid_left / 2, bottom_length- bottom_row_height * 9 + 0.1, font);
chart.addData(ChartProcessor.AXIS_LEFT, "basic_line_bottom_shenggao",0, bottom_length - bottom_row_height *9);
chart.addData(ChartProcessor.AXIS_LEFT, "basic_line_bottom_shenggao",x_length-grid_right, bottom_length - bottom_row_height * 9);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,"basic_line_bottom_shenggao", false);
chart.setLineColor(ChartProcessor.AXIS_LEFT,"basic_line_bottom_shenggao", Color.BLACK);
chart.setLineWidth(ChartProcessor.AXIS_LEFT,"basic_line_bottom_shenggao", ChartShape.LINE_THIN);
for(int i=1;i<5;i++)
{
chart.addBackgroundValue("", grid_left / 2, bottom_length- bottom_row_height * (9+i) + 0.1, font);
chart.addData(ChartProcessor.AXIS_LEFT, "basic_line_bottom_beizhu"+i,0, bottom_length - bottom_row_height *(9+i));
chart.addData(ChartProcessor.AXIS_LEFT, "basic_line_bottom_beizhu"+i,x_length, bottom_length - bottom_row_height * (9+i));
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT, "basic_line_bottom_beizhu"+i, false);
chart.setLineColor(ChartProcessor.AXIS_LEFT, "basic_line_bottom_beizhu"+i, Color.BLACK);
chart.setLineWidth(ChartProcessor.AXIS_LEFT, "basic_line_bottom_beizhu"+i, ChartShape.LINE_THIN);
}
/******************************
* 底部动态数据展示
* ****************************
*/
//begin
List<String> dateList=(List<String>)map.get("dateList"); //日期集合
List<PTempInfo> tempInfoList=(List<PTempInfo>)map.get("tempInfoList"); //体温单集合
for(int i=0;i<dateList.size();i++)
{
PTempInfo resultInfo=null;
if(CollectionUtils.isNotEmpty(tempInfoList))
{
for(PTempInfo tempInfo :tempInfoList)
{
if(dateList.get(i).equals(DateUtil.formatDate(tempInfo.getInspectionDate())))
{
resultInfo=tempInfo;
break;
}
}
if(resultInfo!=null)
{
String weightText="";
if(resultInfo.getWeightType()!=null&&resultInfo.getWeightType().intValue()!=1)
weightText=TwdConstant.WeightType.getName(resultInfo.getWeightType().intValue());
else
weightText=resultInfo.getWeight()==null?"":resultInfo.getWeight().toString();
String heightText="";
if(resultInfo.getHeightType()!=null&&resultInfo.getHeightType().intValue()!=1)
heightText=TwdConstant.HeightType.getName(resultInfo.getHeightType().intValue());
else
heightText=resultInfo.getWeight()==null?"":Math.round(resultInfo.getHeight())+"";
chart.addBackgroundValue(resultInfo.getUrineVolume()==null?"":resultInfo.getUrineVolume()+"",grid_left*(i+1)+ x_unit / 2,bottom_length- bottom_row_height * 3 + 0.1, font); //尿量
chart.addBackgroundValue(resultInfo.getIntake()==null?"":resultInfo.getIntake()+"",grid_left*(i+1)+ x_unit / 2,bottom_length- bottom_row_height * 4 + 0.1, font); //入量
chart.addBackgroundValue(resultInfo.getOutput()==null?"":resultInfo.getOutput()+"",grid_left*(i+1)+ x_unit / 2,bottom_length- bottom_row_height * 5 + 0.1, font); //出量
chart.addBackgroundValue(resultInfo.getPoopCount()==null?"":resultInfo.getPoopCount()+"",grid_left*(i+1)+ x_unit / 2,bottom_length- bottom_row_height * 6 + 0.1, font); //大便次数
chart.addBackgroundValue(resultInfo.getBloodPressure1()==null?"":resultInfo.getBloodPressure1()+"",grid_left*(i+1)+ 1+0.4,bottom_length- bottom_row_height * 7 + 0.1, font); //血压1
chart.addBackgroundValue(resultInfo.getBloodPressure2()==null?"":resultInfo.getBloodPressure2()+"",grid_left*(i+1)+ 5-0.5,bottom_length- bottom_row_height * 7 + 0.1, font); //血压1
chart.addBackgroundValue(weightText,grid_left*(i+1)+ x_unit / 2,bottom_length- bottom_row_height * 8 + 0.1, font); //体重
chart.addBackgroundValue(heightText,grid_left*(i+1)+ x_unit / 2,bottom_length- bottom_row_height * 9 + 0.1, font); //身高
}
}
}
}
/**
* 动态格子数据的初始化
* @param chart
* @param map
*/
public void initGridDynamicData(ChartProcessor chart ,Map map){
//begin
List<String> dateList=(List<String>)map.get("dateList"); //日期集合
List<PTempInfo> tempInfoList=(List<PTempInfo>)map.get("tempInfoList"); //体温单集合
if(CollectionUtils.isEmpty(tempInfoList))
{
return ;
}
for(int i=0;i<dateList.size();i++)
{
PTempInfo resultInfo=null;
for(PTempInfo tempInfo :tempInfoList)
{
if(dateList.get(i).equals(DateUtil.formatDate(tempInfo.getInspectionDate())))
{
resultInfo=tempInfo;
break;
}
}
if(resultInfo!=null)
{
List<PTempDetailInfo> detailInfoList=new ArrayList<PTempDetailInfo>();
detailInfoList.addAll(resultInfo.getDetailInfo());
int k=0;
Integer [] hours=TwdConstant.HOURS;
for(int j=0;j<hours.length;j++) //遍历每天的数据
{
PTempDetailInfo resultDetailInfo=null;
for(PTempDetailInfo detailInfo :detailInfoList)
{
if(hours[j].intValue()==DateUtil.getHour(detailInfo.getInspectionTime()))
{
resultDetailInfo=detailInfo ;
if(detailInfo.getBreathe()!=null)
k++;
break;
}
}
if(resultDetailInfo!=null)
{
/**
* 呼吸
*/
double y_breathe_height=NumberUtil.round(bottom_length- bottom_row_height+((k%2==0)?-bottom_row_height+0.1:0.1)); //如每日记录呼吸2次以上,应当在相应的栏目内上下交错记录
if(resultDetailInfo.getBreathe()!=null&&"1".equals(resultDetailInfo.getBreatheType()+"")) //判断是否使用呼吸机
{
Font aril_font = new Font("黑体", Font.BOLD, 18);
chart.addBackgroundValue("R", grid_left+i*6+grid_col_width/2+j,y_breathe_height, aril_font);
/*String line_name="grid_point_breatherType_"+i+"_"+j;
chart.addData(ChartProcessor.AXIS_LEFT, line_name,grid_left+i*6+grid_col_width/2+j,y_breathe_height+0.1);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,line_name, true);
chart.setLineColor(ChartProcessor.AXIS_LEFT, line_name,Color.BLACK);
chart.setLineShape(ChartProcessor.AXIS_LEFT, line_name,ChartShape.getShape(ChartShape.ROUND, round_size+2,round_size));
chart.setLineVisible(ChartProcessor.AXIS_LEFT, line_name,false);
chart.setLineShapeFilledColor(ChartProcessor.AXIS_LEFT, line_name, Color.WHITE);*/
}
else if(resultDetailInfo.getBreathe()!=null) //正常
{
chart.addBackgroundValue(resultDetailInfo.getBreathe()+"", grid_left+i*6+grid_col_width/2+j,y_breathe_height, font,Color.RED);
}
double grid_temperature_height=0; //体温单对应的y轴值
double grid_pulse_height=0; //脉搏对应的y轴值
double grid_heartRate_height=0; //心率对应的y轴值
boolean temperature_pulse=false; //体温、脉搏重合
boolean pulse_heartRate=false; //脉搏 、心率重合
boolean temperature_heartRate=false; //体温、心率重合
if(resultDetailInfo.getTemperature()!=null)
grid_temperature_height=NumberUtil.round(resultDetailInfo.getTemperature()-(start_temperature-bottom_length));
if(resultDetailInfo.getPulse()!=null)
grid_pulse_height=NumberUtil.round(bottom_length+(resultDetailInfo.getPulse()-20)*0.05);
if(resultDetailInfo.getHeartRate()!=null)
grid_heartRate_height=NumberUtil.round(bottom_length+(resultDetailInfo.getHeartRate()-20)*0.05);
if(Math.abs(NumberUtil.sub(grid_temperature_height, grid_pulse_height))<0.05) //体温 脉搏重合
{
temperature_pulse=true;
grid_temperature_height=grid_pulse_height;
}
if(Math.abs(NumberUtil.sub(grid_pulse_height, grid_heartRate_height))<0.05) //脉搏心率重合
{
pulse_heartRate=true;
grid_pulse_height=grid_heartRate_height;
}
if(Math.abs(NumberUtil.sub(grid_temperature_height, grid_heartRate_height))<0.05) //体温心率重合
{
temperature_heartRate=true;
grid_temperature_height=grid_heartRate_height;
}
/**
* 体温
*/
if(resultDetailInfo.getTemperature()!=null||resultDetailInfo.getTemperatureType().intValue()==4)
{
//画点
String line_name="grid_point_temperatures_"+i+"_"+j;
if(resultDetailInfo.getTemperatureType().intValue()==1) //口温
{
line_name="grid_point_temperatures_kw";
if(temperature_pulse||temperature_heartRate)
line_name="d_grid";
chart.addData(ChartProcessor.AXIS_LEFT, line_name, grid_left+i*6+grid_col_width/2+j,grid_temperature_height);
chart.setLineColor(ChartProcessor.AXIS_LEFT, line_name,Color.BLUE);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,line_name, true);
chart.setLineVisible(ChartProcessor.AXIS_LEFT, line_name,false);
if(temperature_pulse||temperature_heartRate)
chart.setLineShape(ChartProcessor.AXIS_LEFT, line_name,ChartShape.getShape(ChartShape.ROUND, round_size-1,round_size-1));
else
chart.setLineShape(ChartProcessor.AXIS_LEFT, line_name,ChartShape.getShape(ChartShape.ROUND, round_size,round_size));
}
else if(resultDetailInfo.getTemperatureType().intValue()==2) //腋温
{
String line_name1=line_name+"1";
String line_name2=line_name+"2";
if(temperature_pulse||temperature_heartRate)
{
line_name1="g_grid";
line_name2="f_grid";
}
chart.addData(ChartProcessor.AXIS_LEFT, line_name1, grid_left+i*6+grid_col_width/2+j,grid_temperature_height);
chart.addData(ChartProcessor.AXIS_LEFT, line_name2,grid_left+i*6+grid_col_width/2+j,grid_temperature_height);
chart.setLineColor(ChartProcessor.AXIS_LEFT, line_name1, Color.BLUE);
chart.setLineColor(ChartProcessor.AXIS_LEFT, line_name2, Color.BLUE);
chart.setLineShape(ChartProcessor.AXIS_LEFT,line_name1, ChartShape.getLine(ChartShape.LINE, new Point2D.Double(-3,-3), new Point2D.Double(3,3))); //叉
chart.setLineShape(ChartProcessor.AXIS_LEFT, line_name2, ChartShape.getLine(ChartShape.LINE, new Point2D.Double(-3,3), new Point2D.Double(3,-3)));
}
else if(resultDetailInfo.getTemperatureType().intValue()==3) //肛温
{
if(temperature_pulse||temperature_heartRate)
line_name="e_grid";
chart.addData(ChartProcessor.AXIS_LEFT, line_name, grid_left+i*6+grid_col_width/2+j,grid_temperature_height);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,line_name, true);
chart.setLineColor(ChartProcessor.AXIS_LEFT, line_name,Color.BLUE);
chart.setLineVisible(ChartProcessor.AXIS_LEFT, line_name,false);
if(temperature_pulse||temperature_heartRate)
chart.setLineShape(ChartProcessor.AXIS_LEFT, line_name,ChartShape.getShape(ChartShape.ROUND, round_size-1,round_size-1)); //空心蓝圆
else
chart.setLineShape(ChartProcessor.AXIS_LEFT, line_name,ChartShape.getShape(ChartShape.ROUND, round_size,round_size));
chart.setLineShapeFilledColor(ChartProcessor.AXIS_LEFT, line_name, Color.WHITE);
}
else if(resultDetailInfo.getTemperatureType().intValue()==4) //体温不升
{
grid_temperature_height=bottom_length+1-grid_row_height;
chart.addBackgroundValue("不", grid_left+i*6+grid_col_width/2+j,bottom_length+1-grid_row_height, font);
chart.addBackgroundValue("升", grid_left+i*6+grid_col_width/2+j,bottom_length+1-grid_row_height*2, font);
}
if(resultDetailInfo.getReductionTemperature()!=null) //降温后体温
{
double reducationTemperature=NumberUtil.round(resultDetailInfo.getReductionTemperature()-(start_temperature-bottom_length));
//画圈
line_name="grid_point_reductionTemperature_"+i+"_"+j;
chart.addData(ChartProcessor.AXIS_LEFT, line_name, grid_left+i*6+grid_col_width/2+j,reducationTemperature);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,line_name, true);
chart.setLineColor(ChartProcessor.AXIS_LEFT, line_name,Color.RED);
chart.setLineShape(ChartProcessor.AXIS_LEFT, line_name,ChartShape.getShape(ChartShape.ROUND, round_size+3,round_size+3));
chart.setLineVisible(ChartProcessor.AXIS_LEFT, line_name,false);
chart.setLineShapeFilledColor(ChartProcessor.AXIS_LEFT, line_name, Color.WHITE);
line_name="grid_line_reductionTemperature_"+i+"_"+j;
//画虚线
chart.addData(ChartProcessor.AXIS_LEFT, line_name, grid_left+i*6+grid_col_width/2+j,grid_temperature_height);
chart.addData(ChartProcessor.AXIS_LEFT, line_name, grid_left+i*6+grid_col_width/2+j,reducationTemperature);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,line_name, false);
chart.setLineColor(ChartProcessor.AXIS_LEFT, line_name,Color.RED);
chart.setLineWidth(ChartProcessor.AXIS_LEFT,line_name,ChartShape.LINE_WIDE);
chart.setLineDash(ChartProcessor.AXIS_LEFT, line_name,true);
chart.setLineVisible(ChartProcessor.AXIS_LEFT, line_name,true);
}
//画线 >>> 体温不升的时候 不需要画线
if(resultDetailInfo.getTemperatureType().intValue()!=4)
{
chart.addData(ChartProcessor.AXIS_LEFT, "grid_line_temperature", grid_left+i*6+grid_col_width/2+j,grid_temperature_height);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,"grid_line_temperature", false);
chart.setLineColor(ChartProcessor.AXIS_LEFT, "grid_line_temperature",Color.BLUE);
chart.setLineWidth(ChartProcessor.AXIS_LEFT, "grid_line_temperature",ChartShape.LINE_THIN);
chart.setLineVisible(ChartProcessor.AXIS_LEFT, "grid_line_temperature",true);
}
}
/**
* 脉搏
*/
if(resultDetailInfo.getPulse()!=null)
{
//画点
String line_name="grid_point_pulse_"+i+"_"+j;
if(temperature_pulse ) //体温与脉搏重合
line_name="b_grid";
else if(pulse_heartRate)
line_name="c_grid"; //脉搏与心率重合
chart.addData(ChartProcessor.AXIS_LEFT, line_name, grid_left+i*6+grid_col_width/2+j,grid_pulse_height);
if(temperature_pulse) //体温与脉搏重合
{
chart.setLineShape(ChartProcessor.AXIS_LEFT, line_name,ChartShape.getShape(ChartShape.ROUND, round_size+3,round_size+3));
chart.setLineShapeFilledColor(ChartProcessor.AXIS_LEFT, line_name,Color.WHITE);
}
else if(pulse_heartRate) //脉搏与心率重合
{
chart.setLineShape(ChartProcessor.AXIS_LEFT, line_name,ChartShape.getShape(ChartShape.ROUND, round_size-1,round_size-1));
}
else
{
chart.setLineShape(ChartProcessor.AXIS_LEFT, line_name,ChartShape.getShape(ChartShape.ROUND, round_size,round_size));
}
chart.setLineColor(ChartProcessor.AXIS_LEFT, line_name,Color.RED);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,line_name, true);
chart.setLineVisible(ChartProcessor.AXIS_LEFT, line_name,false);
//画线
chart.addData(ChartProcessor.AXIS_LEFT, "grid_line_pulse", grid_left+i*6+grid_col_width/2+j,grid_pulse_height);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,"grid_line_pulse", false);
chart.setLineColor(ChartProcessor.AXIS_LEFT, "grid_line_pulse",Color.RED);
chart.setLineWidth(ChartProcessor.AXIS_LEFT, "grid_line_pulse",ChartShape.LINE_THIN);
chart.setLineVisible(ChartProcessor.AXIS_LEFT, "grid_line_pulse",true);
}
/**
* 心率
*/
if(resultDetailInfo.getHeartRate()!=null)
{
//画点
String line_name="grid_point_heartRate_"+i+"_"+j;
double temperature_breathe_roundsize=round_size;
if(temperature_heartRate||pulse_heartRate) //体温与心率重合 、或者脉搏心率重合
{
line_name="a_grid";
temperature_breathe_roundsize +=3;
}
chart.addData(ChartProcessor.AXIS_LEFT, line_name, grid_left+i*6+grid_col_width/2+j,grid_heartRate_height);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,line_name, true);
chart.setLineColor(ChartProcessor.AXIS_LEFT, line_name,Color.RED);
chart.setLineShape(ChartProcessor.AXIS_LEFT, line_name,ChartShape.getShape(ChartShape.ROUND, temperature_breathe_roundsize,temperature_breathe_roundsize));
chart.setLineVisible(ChartProcessor.AXIS_LEFT, line_name,false);
chart.setLineShapeFilledColor(ChartProcessor.AXIS_LEFT, line_name, Color.WHITE);
//画线
chart.addData(ChartProcessor.AXIS_LEFT, "grid_line_heartRate", grid_left+i*6+grid_col_width/2+j,grid_heartRate_height);
chart.setLineShapeVisible(ChartProcessor.AXIS_LEFT,"grid_line_heartRate", false);
chart.setLineColor(ChartProcessor.AXIS_LEFT, "grid_line_heartRate",Color.RED);
chart.setLineWidth(ChartProcessor.AXIS_LEFT, "grid_line_heartRate",ChartShape.LINE_NORMAL);
chart.setLineVisible(ChartProcessor.AXIS_LEFT, "grid_line_heartRate",true);
}
/**
* 上注释、下注释
*/
if(StringUtils.isNotEmpty(resultDetailInfo.getComment1()))
{
String comment1=TwdConstant.Comment1Type.getName(Long.parseLong(resultDetailInfo.getComment1Type()))+resultDetailInfo.getComment1();
String [] comment1s=new String[comment1.length()];
for(int b=0;b<comment1s.length;b++)
{
comment1s[b]=comment1.substring(b,b+1);
}
for(int a=0;a<comment1s.length;a++)
{
double grid_comment1_height=y_length-top_length-(a+1)*0.2+0.05;
chart.addBackgroundValue(comment1s[a], grid_left+i*6+grid_col_width/2+j, grid_comment1_height,new Font("宋体", Font.LAYOUT_NO_LIMIT_CONTEXT, 11),Color.RED);
}
}
}
}
}
}
//end
}
}
,希望对大家有所帮助,有疑问的联系我。
邮箱:lsq6718686@163.com
jfreechart开发体温单相关推荐
- 体温单怎么画 体温表_准备好承受体温-很多
体温单怎么画 体温表 重点 (Top highlight) Last week, I dropped by my recently reopened gym to restart my lapsed ...
- 记录开发HIS系统体温单的思路历程
记录开发HIS系统体温单的思路历程 一.主要技术:react.es6.svg 二.体温单构成 标题和患者基本信息,固定 日期住院信息等 刻度区及绘图区,也是整个体温单最重要的部分 二.体温单绘制规范 ...
- 医疗系统--体温单(三测单)系统(体温单控件)
不同区域的体温单格式不尽相同,本文以江苏某地体温单为范例,介绍完整的体温单系统开发. 1.名词解释 体温单:又叫三测单,是护理病历的一部分.体温单主要用于记录患者的生命体征及有关情况,内容包括患者姓名 ...
- html 绘制体温单,使用zrender.js绘制体温单(2)
今天我们来画折线图 效果图 以下为模拟数据 [{"time":19,"text":"入\n院\n19\n时\n11\n分","po ...
- 体温单源码 delphi体温单源码 又叫三测单
体温单:又叫三测单,是护理病历的一部分.体温单主要用于记录患者的生命体征及有关情况,内容包括患者姓名.年龄.性别.科别.床号.入院日期.住院号(或病案号).日期.住院天数.手术后天数.脉搏.呼吸.体温 ...
- vue+zrender实现医院体温单
项目背景 医院医护项目需求,需要用H5做一个通用的体温单 项目演示链接 版本一 版本二 项目代码简介 由vue-cli4脚手架快速搭建生成,主要代码都在thermometer.vue文件里面,后续修改 ...
- Delphi最新版电子体温单源码(免控件)
不同区域的体温单格式不尽相同,本文以江苏某地体温单为范例,介绍完整的体温单系统开发. 1.名词解释 体温单:又叫三测单,是护理病历的一部分.体温单主要用于记录患者的生命体征及有关情况,内容包括患者姓名 ...
- vue 绘制体温单与三测单组件 实现前端js打印
更新: 代码开源 https://github.com/mydaoyuan/my-development 有帮助请帮忙点个 start .企鹅:1534815114 如何使用chatGPT辅助开发复杂 ...
- 开源C#2.0体温单程序
开源的C#2.0体温单程序,开发性好,可灵活配置,可打印,程序短小精练,不依赖任何第三方组件,已经封装成WinForm控件,可直接用于.NET程序开发. 所有的C#源代码下载地址 http://fil ...
最新文章
- 【jsp】写jsp文件的准备
- eclipse:快捷键(补充。。。)
- linux mysql主主复制_MySQL主从复制与主主复制
- 我的微信luogantt
- mapreduce编程实例(1)-统计词频
- STM32F0308DISCOVERY探索套件
- SQL Sever 性能调优
- 计算机在智慧交通的应用论文,智能交通的毕业论文
- array python 交集_Python基础(二)——列表和元组
- 详解Linux环境软RAID 5建立过程
- 怕死吗?研究人员推出可模拟“灵魂出窍”的VR系统
- Spring中的Bean是如何被回收的?
- 【协作通信】基于matlab协作通信仿真【含Matlab源码 1006期】
- 福建土楼ppt计算机二级,福建土楼PPT.ppt
- 基于Spring Boot 2.5.1 微服务框架发布(Eurynome Cloud )
- 笔记-首次参加数据挖掘比赛摸索的经验(赛题为CCF-BDCI2017企业经营退出风险预测)
- android view.setVisibility 不显示问题
- unix纪元 OpenJ_Bailian - 3860
- 苹果手机的OLED屏和LCD屏有什么区别?
- Nginx学习部署环境(六)-Nginx原理