流量统计csv增加标题时间,最后增加统计
This commit is contained in:
@@ -270,7 +270,7 @@
|
||||
type : 'string',
|
||||
value : '<spring:message code="total"></spring:message>'
|
||||
})
|
||||
var total = total = JSON.parse($("#total").val());
|
||||
var total = JSON.parse($("#total").val());
|
||||
a.push({
|
||||
type : "number",
|
||||
value : total
|
||||
@@ -285,6 +285,56 @@
|
||||
};
|
||||
}(Highcharts));
|
||||
|
||||
(function(H) {
|
||||
H.Chart.prototype.downloadCSV = function() {
|
||||
var rows = this.getDataRows(true);
|
||||
var data=new Array();
|
||||
var total = total = JSON.parse($("#total").val());
|
||||
$(rows).each(function (i,d){
|
||||
if(d!=null){
|
||||
data.push({
|
||||
num1:d[0],
|
||||
num2:d[1]
|
||||
})
|
||||
}
|
||||
})
|
||||
data.push({
|
||||
num1:"<spring:message code='total'/>",
|
||||
num2:total
|
||||
})
|
||||
var start = $("#beginDate").val();
|
||||
var end = $("#endDate").val();
|
||||
exportCsv({
|
||||
title:["<spring:message code='${searchAction}'/>",start+"--"+end],
|
||||
titleForKey:["num1","num2"],
|
||||
data:data
|
||||
});
|
||||
};
|
||||
}(Highcharts));
|
||||
|
||||
function exportCsv(obj){
|
||||
//title ["","",""]
|
||||
var title = obj.title;
|
||||
//titleForKey ["","",""]
|
||||
var titleForKey = obj.titleForKey;
|
||||
var data = obj.data;
|
||||
var str = [];
|
||||
str.push(obj.title.join(",")+"\n");
|
||||
for(var i=0;i<data.length;i++){
|
||||
var temp = [];
|
||||
for(var j=0;j<titleForKey.length;j++){
|
||||
temp.push(data[i][titleForKey[j]]);
|
||||
}
|
||||
str.push(temp.join(",")+"\n");
|
||||
}
|
||||
var uri = 'data:text/csv;charset=utf-8,' + encodeURIComponent(str.join(""));
|
||||
var downloadLink = document.createElement("a");
|
||||
downloadLink.href = uri;
|
||||
downloadLink.download = "<spring:message code='${searchAction}'/>"+".csv";
|
||||
document.body.appendChild(downloadLink);
|
||||
downloadLink.click();
|
||||
document.body.removeChild(downloadLink);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -54,7 +54,7 @@
|
||||
<input id="searchAction" name="searchAction" type="hidden" value="${searchAction}"/>
|
||||
<input id="beginDateh" type="hidden" value="${beginDate}"/>
|
||||
<input id="endDateh" type="hidden" value="${endDate}"/>
|
||||
|
||||
<input id="total" type="hidden"/>
|
||||
</div>
|
||||
<script src="${pageContext.request.contextPath}/static/global/plugins/highcharts/js/highcharts.js"></script>
|
||||
<script src="${pageContext.request.contextPath}/static/global/plugins/highcharts/js/exporting.js"></script>
|
||||
@@ -180,9 +180,13 @@ function showActionTransChart(xData,series){
|
||||
success:function (rs) {
|
||||
var xData=new Array();
|
||||
var series=new Array();
|
||||
var total=[];
|
||||
if(rs!=null&&rs.length>0){
|
||||
xData=rs[0].statTime;
|
||||
$(rs).each(function(i, d) {
|
||||
total.push(
|
||||
sum(d.count)
|
||||
)
|
||||
var entrance="";
|
||||
if(d!=null&&d.entranceId==1){
|
||||
entrance="Astana";
|
||||
@@ -202,7 +206,7 @@ function showActionTransChart(xData,series){
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
$("#total").val(JSON.stringify(total));
|
||||
showActionTransChart(xData,series);
|
||||
closeTip();
|
||||
},
|
||||
@@ -277,6 +281,64 @@ function showActionTransChart(xData,series){
|
||||
});
|
||||
};
|
||||
}(Highcharts));
|
||||
(function(H) {
|
||||
H.Chart.prototype.downloadCSV = function() {
|
||||
var rows = this.getDataRows(true);
|
||||
var data=new Array();
|
||||
var total = JSON.parse($("#total").val());
|
||||
$(rows).each(function (i,d){
|
||||
if(d!=null){
|
||||
if(i>0){
|
||||
data.push({
|
||||
num1:d[0],
|
||||
num2:d[1],
|
||||
num3:d[2],
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
data.push({
|
||||
num1:"<spring:message code='total'/>",
|
||||
num2:total
|
||||
})
|
||||
var start = $("#beginDate").val();
|
||||
var end = $("#endDate").val();
|
||||
exportCsv({
|
||||
title:["<spring:message code='${searchAction}'/>",start+"--"+end],
|
||||
titleForKey:["num1","num2","num3"],
|
||||
data:data
|
||||
});
|
||||
};
|
||||
}(Highcharts));
|
||||
|
||||
function exportCsv(obj){
|
||||
//title ["","",""]
|
||||
var title = obj.title;
|
||||
//titleForKey ["","",""]
|
||||
var titleForKey = obj.titleForKey;
|
||||
var data = obj.data;
|
||||
var str = [];
|
||||
str.push(obj.title.join(",")+"\n");
|
||||
for(var i=0;i<data.length;i++){
|
||||
var temp = [];
|
||||
for(var j=0;j<titleForKey.length;j++){
|
||||
temp.push(data[i][titleForKey[j]]);
|
||||
}
|
||||
str.push(temp.join(",")+"\n");
|
||||
}
|
||||
var uri = 'data:text/csv;charset=utf-8,' + encodeURIComponent(str.join(""));
|
||||
var downloadLink = document.createElement("a");
|
||||
downloadLink.href = uri;
|
||||
downloadLink.download = "<spring:message code='${searchAction}'/>"+".csv";
|
||||
document.body.appendChild(downloadLink);
|
||||
downloadLink.click();
|
||||
document.body.removeChild(downloadLink);
|
||||
}
|
||||
function sum(arr) {
|
||||
return arr.reduce(function(prev, curr, idx, arr){
|
||||
return prev + curr;
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user