JS文件:
var chart; var json = { chart: { renderTo: 'container', defaultSeriesType: 'line', marginRight: 130, marginBottom: 25 }, title: { text: '血压', x: -20 //center }, subtitle: { text: '血压折线图', x: -20 }, xAxis: { categories: [] }, yAxis: { title: { text: '血压范围 (mmhg)' }, plotLines: [{ value: 0, width: 1, color: '#808080' }] }, tooltip: { formatter: function() { return '<b>'+ this.series.name +'</b><br/>'+ this.x +': '+ this.y +''; } }, legend: { layout: 'vertical', align: 'right', verticalAlign: 'top', x: -10, y: 200, borderWidth: 0 }, series: [{ name: '低血压', data: [] }, { name: '高血压', data: [] }] }; //var x1 = [154,125,142,179,177,132,77,82]; // var y1 = [135,96,83,99,119,149,155,86]; $(document).ready(function() { $.ajax({ type : "post", url : "pressure!queryHistoryPressure.action", data : { typeID :'1', userID :'00101', }, dataType : "json", success : function(data) { json.xAxis.categories = data.categories_date; json.series[0].data = data.categories_bloodsystolic; json.series[1].data = data.categories_diastolic; chart = new Highcharts.Chart(json); } }); });
后台文件:
/** * <project>hansci_search</project> * <package>com.hansci.search.action</package> * <class>IssuedAction.java</class> * @time:2013-3-1 下午12:27:08 * */ package com.neowave.health.action; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Resource; import org.apache.commons.lang.ObjectUtils; import org.apache.log4j.Logger; import com.hansci.base.action.BaseAction; import com.neowave.health.bean.HistoryBloodPressure; import com.neowave.health.entity.NeowaveBloodPressure; import com.neowave.health.entity.NeowaveUser; import com.neowave.health.entity.NeowaveUserInfo; import com.neowave.health.service.HealthBloodPressureService; import com.neowave.health.util.WebConstant; import com.opensymphony.xwork2.ActionContext; public class PressureAction extends BaseAction { private static final long serialVersionUID = 1217029936556299526L; private Logger log = Logger.getLogger(PressureAction.class); private NeowaveBloodPressure neowaveBloodPressure; private List<NeowaveBloodPressure> neowaveBloodPressures; private String typeID; private String userID; private HistoryBloodPressure historyBloodPressure; @Resource private HealthBloodPressureService healthBloodPressureService; private SimpleDateFormat format = new SimpleDateFormat("dd"); public String execute() { ActionContext ctx = ActionContext.getContext(); log.info("---------------"+ctx.getSession().get(WebConstant.USER_ID)); String userID = ObjectUtils.toString(ctx.getSession().get(WebConstant.USER_ID),""); log.info("---------typeID="+typeID); //获取血压的历史值 neowaveBloodPressures = healthBloodPressureService.getHistoryMonitor(userID, Integer.parseInt(typeID)); log.info("-------neowaveBloodPressures.size="+neowaveBloodPressures.size()); String bloodsystolic = ""; String diastolic=""; String categories=""; if(null!=neowaveBloodPressures&&neowaveBloodPressures.size()>0) { for(NeowaveBloodPressure bps:neowaveBloodPressures) { categories+="'"+format.format(bps.getBloodTime())+"日',"; bloodsystolic+=bps.getBloodSystolic()+","; diastolic+=bps.getBloodDiastolic()+","; } } categories = categories.substring(0, categories.length()-1); bloodsystolic = bloodsystolic.substring(0, bloodsystolic.length()-1); diastolic = diastolic.substring(0, diastolic.length()-1); historyBloodPressure = new HistoryBloodPressure(); historyBloodPressure.setCategories(categories); historyBloodPressure.setSystolic(bloodsystolic); historyBloodPressure.setDiastolic(diastolic); log.info(historyBloodPressure.getCategories()); log.info(historyBloodPressure.getDiastolic()); log.info(historyBloodPressure.getSystolic()); Map<String, String> jsonMap = new HashMap<String, String>(); jsonMap.put("categories_date", categories); return LIST; } @SuppressWarnings("unchecked") public String queryHistoryPressure() { Map jsonMap = new HashMap(); // ActionContext ctx = ActionContext.getContext(); // log.info("---------------"+ctx.getSession().get(WebConstant.USER_ID)); // // String userID = ObjectUtils.toString(ctx.getSession().get(WebConstant.USER_ID),""); log.info("---------typeID="+typeID); //获取血压的历史值 neowaveBloodPressures = healthBloodPressureService.getHistoryMonitor(userID, Integer.parseInt(typeID)); log.info("-------neowaveBloodPressures.size="+neowaveBloodPressures.size()); String bloodsystolic = ""; String diastolic=""; String categories=""; List categories_date = new ArrayList(); List total = new ArrayList(); List categories_bloodsystolic = new ArrayList(); List categories_diastolic = new ArrayList(); if(null!=neowaveBloodPressures&&neowaveBloodPressures.size()>0) { for(NeowaveBloodPressure bps:neowaveBloodPressures) { categories_date.add(format.format(bps.getBloodTime())+"日"); categories_bloodsystolic.add(Integer.parseInt(ObjectUtils.toString(bps.getBloodSystolic(), ""))); categories_diastolic.add(Integer.parseInt(ObjectUtils.toString(bps.getBloodDiastolic(), ""))); bloodsystolic+=bps.getBloodSystolic()+","; diastolic+=bps.getBloodDiastolic()+","; } } String bs_str = bloodsystolic; bloodsystolic = bloodsystolic.substring(0, bloodsystolic.length()-1); bloodsystolic = "name: '低压',data:["+bloodsystolic+"]"; diastolic = diastolic.substring(0, diastolic.length()-1); diastolic = "name: '高压',data:["+diastolic+"]"; log.info(bloodsystolic); log.info(diastolic); total.add(bloodsystolic); total.add(diastolic); //jsonMap.put("categories_date", categories); jsonMap.put("categories_date", categories_date); jsonMap.put("categories_bloodsystolic", categories_bloodsystolic); jsonMap.put("categories_diastolic", categories_diastolic); jsonMap.put("bloodsystolic", bloodsystolic); jsonMap.put("diastolic", diastolic); jsonMap.put("bs_str", bs_str); //{"categories_date":['19日','20日','21日','22日','23日','24日','25日','26日'} return this.ajaxJson(jsonMap); } public NeowaveBloodPressure getNeowaveBloodPressure() { return neowaveBloodPressure; } public void setNeowaveBloodPressure(NeowaveBloodPressure neowaveBloodPressure) { this.neowaveBloodPressure = neowaveBloodPressure; } public List<NeowaveBloodPressure> getNeowaveBloodPressures() { return neowaveBloodPressures; } public void setNeowaveBloodPressures( List<NeowaveBloodPressure> neowaveBloodPressures) { this.neowaveBloodPressures = neowaveBloodPressures; } public String getTypeID() { return typeID; } public void setTypeID(String typeID) { this.typeID = typeID; } public HistoryBloodPressure getHistoryBloodPressure() { return historyBloodPressure; } public void setHistoryBloodPressure(HistoryBloodPressure historyBloodPressure) { this.historyBloodPressure = historyBloodPressure; } public String getUserID() { return userID; } public void setUserID(String userID) { this.userID = userID; } }