jsp页面
JavaScript
function refreshChar() {
var url = "actions/backLog!countUpSiteCustomerNumber.action";
$.getJSON(url,function(data) {
var chart = new Highcharts.Chart(data);
});
}
refreshChar();
Html
<div class="row-fluid">
<article class="span12">
<div class="jarviswidget" id="widget-id-0">
<header>
<h2>网站新增用户量分析</h2>
</header>
<div>
<div class="inner-spacer">
<div id="container" class="chart has-legend" style="min-width:600px;height:25%;"></div>
</div>
</div>
</div>
</article>
</div>
Java
/**
* 统计近半年每个月的用户量
*/
public void countUpSiteCustomerNumber() {
try {
List<Map<String, Object>> mapLists = backLogManager.findSiteCustomerList();
List<String> categories= new ArrayList<String>();
List<Integer> personal_cnt = new ArrayList<Integer>();
List<Integer> enterprise_cnt = new ArrayList<Integer>();
List<Integer> lawyer_cnt = new ArrayList<Integer>();
List<Integer> lawyers_cnt = new ArrayList<Integer>();
for (Map<String, Object> mapList : mapLists) {
categories.add(mapList.get("YEAR_MONTH").toString());
personal_cnt.add(Integer.valueOf(mapList.get("PERSONAL_CNT").toString()));
enterprise_cnt.add(Integer.valueOf(mapList.get("ENTERPRISE_CNT").toString()));
lawyer_cnt.add(Integer.valueOf(mapList.get("LAWYER_CNT").toString()));
lawyers_cnt.add(Integer.valueOf(mapList.get("LAWYERS_CNT").toString()));
}
Chart chart = new Chart();
chart.setRenderTo("container");
chart.setType(ChartType.spline);
Title title = new Title();
title.setText("");
title.setX(0);
XAxis xAxis = new XAxis();
xAxis.setCategories(categories);
YAxis yAxis = new YAxis();
Title yTitle = new Title();
yTitle.setText("用户数量");
yAxis.setTitle(yTitle);
yAxis.setMin(0);
Credits credits = new Credits();
credits.setText("http://www.gzac.org");
credits.setHref("http://www.gzac.org");
List<Serie> series = new ArrayList<Serie>();
series.add(new Serie("个人", personal_cnt));
series.add(new Serie("企业", enterprise_cnt));
series.add(new Serie("律师", lawyer_cnt));
series.add(new Serie("律师所", lawyers_cnt));
Highchart highchart = new Highchart();
highchart.setCredits(credits);
highchart.setChart(chart);
highchart.setTitle(title);
highchart.setxAxis(xAxis);
highchart.setyAxis(yAxis);
highchart.setSeries(series);
Struts2Utils.renderJson(highchart);
} catch (Exception e) {
logger.error("统计近半年每个月的用户量出错", e);
}
}
Highchart.java
public class Highchart implements java.io.Serializable {
private static final long serialVersionUID = -5880168163194932425L;
private Chart chart;
private Title title;
private XAxis xAxis;
private YAxis yAxis;
private List<Serie> series;
private Credits credits;
public Chart getChart() {
return chart;
}
public void setChart(Chart chart) {
this.chart = chart;
}
public Title getTitle() {
return title;
}
public void setTitle(Title title) {
this.title = title;
}
public XAxis getxAxis() {
return xAxis;
}
public void setxAxis(XAxis xAxis) {
this.xAxis = xAxis;
}
public YAxis getyAxis() {
return yAxis;
}
public void setyAxis(YAxis yAxis) {
this.yAxis = yAxis;
}
public List<Serie> getSeries() {
return series;
}
public void setSeries(List<Serie> series) {
this.series = series;
}
public Credits getCredits() {
return credits;
}
public void setCredits(Credits credits) {
this.credits = credits;
}
}
Sql
省略一万字
由于图表的属性对应到实体类,由此产生的实体类非常多的。如果我们需要改变图表的某些样式,就需要通过修改实体类文件。因此本人觉得开发效率是非常低的,建议大家后台只取数据即可。