打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
JSP通过hignChart生成线状图-鼠标在图上时可以显示此时时间和此时对应的值

Controller端处理:
@RequestMapping(value="/ShowLineChartFundProfit/{comId}/{beginDate}/{endDate}")
public String ShowLineChartFundProfit(Model model,HttpServletRequest request,@PathVariable("comId") int comId,@PathVariable("beginDate") String beginDate,@PathVariable("endDate") String endDate){
FundCombination fundCombination = fundConbinationService.findFundCombinationById(comId);
Map<String, Object> params = new HashMap<String, Object>();
params.put("comId", comId);
params.put("beginDate", beginDate);
params.put("endDate", endDate);
List<AchievementCompare> achievementCompareList = exportFundFigureService.selectAchievementCompareProfitList(params);
List<FundCombination> fundCombinationList = exportFundFigureService.selectFundCombinationProfitList(params);
model.addAttribute("beginDate", beginDate);
model.addAttribute("endDate", endDate);
model.addAttribute("fundCombination", fundCombination);
model.addAttribute("achievementCompareList", achievementCompareList);
model.addAttribute("fundCombinationList", fundCombinationList);
return "calculate/showLineChartProfit.jsp";
}

对应的两个实体类:
public class AchievementCompare implements Serializable {
private static final long serialVersionUID = -9007219246488771811L;
private int id;
private String indexCode;  //业绩比较基准代码
private String indexName;  //业绩比较基准名称,如:中证100
private String rateDecimal;  //比例
private String remark;  //备注
private String comName;  //所在组合名称
private int comId;  //所在组合id
private String profitDate;   //显示线状收益图时的收益时间
private float profitRate;   //显示线状收益图是的收益率
public int getId() {
return id;
}
......
}
public class FundCombination implements Serializable {
private static final long serialVersionUID = -8040081446231402509L;
private int id;
private String comName;  //组合名称
private String createTime;  //创建时间
private String createName;  //创建人
private String property; //组合属性,'1'表示长期组合,'0'表示短期组合
private String description;  //组合描述
private int isPool; //0:表示基金组合,1:表示基金池
private String profitDate;   //显示线状收益图时的收益时间
private float profitRate;   //显示线状收益图是的收益率
public int getId() {
return id;
}
......
}

对应显示的JSP页面showLineChartProfit.jsp

<head>
<script src="//cdn.staticfile.org/highcharts/4.0.1/highcharts.js"></script>
</head>
<div class="container-fluid">
<div class="row-fluid">
<h5></h5>
</div>
<div class="row-fluid">
<div class="span12">
<div class="container-fluid">
</div>
<div class="container-fluid">
<div class="control-group">
<label class="control-label">启始日期</label>
<div class="controls input-append date form_date">
<input name="beginDate" id="beginDate" size="16" type="text"
value="${beginDate}" readonly> <span class="add-on"><i
class="icon-remove"></i></span> <span class="add-on"><i
class="icon-th"></i></span>
</div>
</div>
<div class="control-group">
<label class="control-label">结束日期</label>
<div class="controls input-append date form_date">
<input name="endDate" id="endDate" size="16" type="text"
value="${endDate}" readonly> <span class="add-on"><i
class="icon-remove"></i></span> <span class="add-on"><i
class="icon-th"></i></span>
</div>
</div>

<button type="submit" name="asdd" onclick="generateChart()" class="btn btn-primary">生成图表</button>
<input name="返回上一页" type=button id="" class="btn btn-primary" onClick="history.back(-1)" value="返回上一页" >
<div id="chart" style="height:300px;">
</div>
</div>
</div>

</div>
</div>

<script type="text/javascript">
function generateChart(){
  var comId = ${fundCombination.id};
  var beginDate = $("#beginDate").val();
  var endDate = $("#endDate").val();
  var url = "/yilucaifu-research/tool/ShowLineChartFundProfit/" + comId + "/" + beginDate + "/" + endDate + ".do";
  window.location.href = url;
  }
</script>

<script type="text/javascript">
var data1=[<c:forEach items="${achievementCompareList}" varStatus="status"  var="item">
[new Date(('${item.profitDate}')*1000).getTime(),parseFloat('${item.profitRate}')]
<c:if test="${(status.index+1)!=fn:length(achievementCompareList)}">,</c:if>
 </c:forEach>];

var data2=[<c:forEach items="${fundCombinationList}" varStatus="status"  var="item">
[new Date(('${item.profitDate}')*1000).getTime(),parseFloat('${item.profitRate}')]
            <c:if test="${(status.index+1)!=fn:length(fundCombinationList)}">,</c:if>
           </c:forEach>];
$('#chart').highcharts(
{
     colors: [
       '#ffbb40',
       '#a43838'
     ],
     title: {
       text: "线性收益图"
     },
     tooltip: {
       crosshairs: !0,
       formatter: function () {
         var date = new Date(this.x),
         time = date.getFullYear() + '年' + (date.getMonth() + 1) + '月' + date.getDate() + '日',
         fundName = this.series.name;
         return time + '<br/>' + fundName + ':<strong>' + this.y.toFixed(2) + '</strong>%<br/>'
       }
     },
     xAxis: {
       type: 'datetime',
       gridLineWidth: 1,
       labels: {
         formatter: function () {
           return '  ' + Highcharts.dateFormat('%Y-%m-%d', this.value) + '  '
         }
       }
     },
     yAxis: {
       title: {
         text: '收益率(%)'
       },
       labels: {
         formatter: function () {
           return this.value + '%'
         }
       }
     },
     plotOptions: {
       line: {
         marker: {
           radius: 0,
           lineColor: '#666666',
           lineWidth: 1
         },
         shadow: !1,
         lineWidth: 2
       }
     },
     series: [
       {
         name: "比较基准",
         marker: {
           symbol: 'square'
         },
         data: data1
       },
       {
         name: '收益图',
         marker: {
           symbol: 'diamond'
         },
         data: data2
       }
     ],
     credits: {
       enabled: true
     }
   }
);
</script>


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
《JAVA与模式》之建造模式
JPA IN用法
深入浅出Java MVC(Model View Controller)
JSP中文验证码源码以及乱码问题
数据统计如何去除非工作时间(比如下班时间后,星期六,日,节假日)
java得到日期相减的天数
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服