日期:2014-05-17  浏览次数:20823 次

highcharts
我在action中拼接series数据public String getInfo(){
List<AttentionReport> list=homePageService.getInfo(year, month);

StringBuffer sb=new StringBuffer();
sb.append("[{name: '关注数',data:[");
for(AttentionReport c:list){
sb.append(c.getAttentionNumber());
sb.append(",");
}
sb.append("'']},{name:'取消关注数',data:[");
for(AttentionReport c:list){
sb.append(c.getUnfollowNumber());
sb.append(",");
}
sb.append("'']},{name:'净增长数',data:[");
for(AttentionReport c:list){
sb.append(c.getAttentionNumber()-c.getUnfollowNumber());
sb.append(",");
}
sb.append("'']}]");
System.out.println(sb.toString());
/*for(AttentionReport c:list){
System.out.println(c.getAttentionNumber()+","+c.getUnfollowNumber()+","+c.getTime());
}*/
HttpServletRequest request=ServletActionContext.getRequest();
request.setAttribute("sb", sb);
return SUCCESS;
}
返回给jsp页面通过request获取<input type="hidden" value="<%=request.getAttribute("sb")%>" id="sb"/>
最后将数据给series
$(function () {
   $('#basic_line_test').highcharts({
        title: {
            text:'用户关注报告',
            x: -20 //center
        },
        subtitle: {
        },
        xAxis: {
            categories: []
        },
        yAxis: {
            title: {
                text: '关注次数'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        tooltip: {
            valueSuffix: '次'
        },
        credits: { 
         enabled: false 
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'middle',
            borderWidth: 0
        },