1
我有一些Google圖表在Apache Tomcat 5服務器上讀取CSV。加快谷歌圖表 - Apache Tomcat 5.5緩存
負載需要很長時間(15秒顯示圖表)。
有誰知道我會如何加快速度?
也許在tomcat 5.5上緩存?
代碼如下
function FwThroughputStacked(){
$.get("../Data_Access/Overall_Fortinet_DLUL_Throughput_Report.csv", function(csvString) {
var arrayData = $.csv.toArrays(csvString, {onParseValue: $.csv.hooks.castToScalar});
var data = new google.visualization.arrayToDataTable(arrayData);
var DLThroughputView = new google.visualization.DataView(data);
DLThroughputView.setColumns([0,1,2,3,4,5,6,7,8,9,10]);
var ULThroughputView = new google.visualization.DataView(data);
ULThroughputView.setColumns([0,11,12,13,14,15,16,17,18,19]);
var ULThroughputStackedOps = {
chartArea: {width: '80%', height: '75%'},
explorer: {actions: ["dragToZoom", "rightClickToReset"]},
isStacked: true,
hAxis: {title: data.getColumnLabel(0), minValue: data.getColumnRange(0).min, maxValue: data.getColumnRange(0).max, textStyle: {fontSize: 9}},
vAxis: {title: "Megabits/s", minValue: data.getColumnRange(11).min, maxValue: data.getColumnRange(11).max, textStyle: {fontSize: 10}},
legend: {position: 'top', maxLines: 10, textStyle: {fontSize: 9} },
};
var ULThroughputOps = {
chartArea: {width: '80%', height: '75%'},
explorer: {actions: ["dragToZoom", "rightClickToReset"]},
hAxis: {title: data.getColumnLabel(0), minValue: data.getColumnRange(0).min, maxValue: data.getColumnRange(0).max, textStyle: {fontSize: 9}},
vAxis: {title: "Megabits/s", minValue: data.getColumnRange(11).min, maxValue: data.getColumnRange(11).max, textStyle: {fontSize: 10}},
legend: {position: 'top', maxLines: 10, textStyle: {fontSize: 9} },
};
var DLThroughputOps = {
chartArea: {width: '80%', height: '75%'},
explorer: {actions: ["dragToZoom", "rightClickToReset"]},
hAxis: {title: data.getColumnLabel(0), minValue: data.getColumnRange(0).min, maxValue: data.getColumnRange(0).max, textStyle : {fontSize: 9}},
vAxis: {title: "Megabits/s", minValue: data.getColumnRange(1).min, maxValue: data.getColumnRange(1).max, textStyle : {fontSize: 10}},
legend: {position: 'top', maxLines: 10, textStyle: {fontSize: 9} },
};
var DLThroughputStackedOps = {
chartArea: {width: '80%', height: '75%'},
explorer: {actions: ["dragToZoom", "rightClickToReset"]},
isStacked: true,
hAxis: {title: data.getColumnLabel(0), minValue: data.getColumnRange(0).min, maxValue: data.getColumnRange(0).max, textStyle: {fontSize: 9}},
vAxis: {title: "Megabits/s", minValue: data.getColumnRange(1).min, maxValue: data.getColumnRange(1).max, textStyle: {fontSize: 10}},
legend: {position: 'top', maxLines: 10, textStyle: {fontSize: 9} },
};
var chart = new google.visualization.LineChart(document.getElementById('DLThroughput'));
chart.draw(DLThroughputView, DLThroughputOps);
var chart = new google.visualization.AreaChart(document.getElementById('DLThroughputStacked'));
chart.draw(DLThroughputView, DLThroughputStackedOps);
var chart = new google.visualization.AreaChart(document.getElementById('throughputStacked'));
chart.draw(ULThroughputView, ULThroughputStackedOps);
var chart = new google.visualization.LineChart(document.getElementById('throughput'));
chart.draw(ULThroughputView, ULThroughputOps);
});
}
你知道下載csv和運行上面的函數需要多長時間? csv中有多少行? – WhiteHat
這是一個很大的CSV,由我們的一個系統每小時自動生成一次。 CSV下載佔用大部分時間 - 所以我想知道我們是否可以以某種方式緩存Google圖表 - 因此它不會在每次刷新時重新加載,而是每隔一小時重新加載一次。 – Kieran
您可以使用'chart.getImageURI()'來生成圖表中的圖像並將其顯示出來,直到需要刷新爲止 - [這裏是一個示例](http://stackoverflow.com/a/38464203/5090771) – WhiteHat