Merge pull request #136 from lanrenwo/home_charts

解决图表切换的卡顿问题
This commit is contained in:
bjdgyc 2022-09-15 14:21:42 +08:00 committed by GitHub
commit 7b3507d962
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 38 additions and 27 deletions

View File

@ -217,50 +217,61 @@ export default {
}); });
}, },
formatOnline(data) { formatOnline(data) {
let timeFormat = data.scope == "rt" || data.scope == "1h" || data.scope == "24h" ? "h:i:s" : "m/d h:i:s" let timeFormat = this.getTimeFormat(data.scope)
let chartData = this.lineChart[data.action]
let datas = data.datas let datas = data.datas
this.lineChart.online.xname = [] chartData.xname = []
this.lineChart.online.xdata["在线人数"] = [] chartData.xdata["在线人数"] = []
for(var i=0; i<datas.length;i++){ for(var i=0; i<datas.length;i++){
this.lineChart.online.xname[i] = this.dateFormat(datas[i].created_at, timeFormat) chartData.xname[i] = this.dateFormat(datas[i].created_at, timeFormat)
this.lineChart.online.xdata["在线人数"][i] = datas[i].num chartData.xdata["在线人数"][i] = datas[i].num
} }
// 线 // 线
if (data.scope == "rt") { if (data.scope == "rt") {
this.counts.online = datas[datas.length - 1].num this.counts.online = datas[datas.length - 1].num
} }
this.lineChart[data.action] = chartData
}, },
formatNetwork(data) { formatNetwork(data) {
let timeFormat = data.scope == "rt" || data.scope == "1h" || data.scope == "24h" ? "h:i:s" : "m/d h:i:s" let timeFormat = this.getTimeFormat(data.scope)
let chartData = this.lineChart[data.action]
let datas = data.datas let datas = data.datas
this.lineChart.network.xname = [] chartData.xname = []
this.lineChart.network.xdata["上行流量"] = [] chartData.xdata["上行流量"] = []
this.lineChart.network.xdata["下行流量"] = [] chartData.xdata["下行流量"] = []
for(var i=0; i<datas.length;i++){ for(var i=0; i<datas.length;i++){
this.lineChart.network.xname[i] = this.dateFormat(datas[i].created_at, timeFormat) chartData.xname[i] = this.dateFormat(datas[i].created_at, timeFormat)
this.lineChart.network.xdata["上行流量"][i] = this.toMbps(datas[i].up) chartData.xdata["上行流量"][i] = this.toMbps(datas[i].up)
this.lineChart.network.xdata["下行流量"][i] = this.toMbps(datas[i].down) chartData.xdata["下行流量"][i] = this.toMbps(datas[i].down)
} }
this.lineChart[data.action] = chartData
}, },
formatCpu(data) { formatCpu(data) {
let timeFormat = data.scope == "rt" || data.scope == "1h" || data.scope == "24h" ? "h:i:s" : "m/d h:i:s" let timeFormat = this.getTimeFormat(data.scope)
let chartData = this.lineChart[data.action]
let datas = data.datas let datas = data.datas
this.lineChart.cpu.xname = [] chartData.xname = []
this.lineChart.cpu.xdata["CPU"] = [] chartData.xdata["CPU"] = []
for(var i=0; i<datas.length;i++){ for(var i=0; i<datas.length;i++){
this.lineChart.cpu.xname[i] = this.dateFormat(datas[i].created_at, timeFormat) chartData.xname[i] = this.dateFormat(datas[i].created_at, timeFormat)
this.lineChart.cpu.xdata["CPU"][i] = this.toDecimal(datas[i].percent) chartData.xdata["CPU"][i] = this.toDecimal(datas[i].percent)
} }
this.lineChart[data.action] = chartData
}, },
formatMem(data) { formatMem(data) {
let timeFormat = data.scope == "rt" || data.scope == "1h" || data.scope == "24h" ? "h:i:s" : "m/d h:i:s" let timeFormat = this.getTimeFormat(data.scope)
let chartData = this.lineChart[data.action]
let datas = data.datas let datas = data.datas
this.lineChart.mem.xname = [] chartData.xname = []
this.lineChart.mem.xdata["内存"] = [] chartData.xdata["内存"] = []
for(var i=0; i<datas.length;i++){ for(var i=0; i<datas.length;i++){
this.lineChart.mem.xname[i] = this.dateFormat(datas[i].created_at, timeFormat) chartData.xname[i] = this.dateFormat(datas[i].created_at, timeFormat)
this.lineChart.mem.xdata["内存"][i] = this.toDecimal(datas[i].percent) chartData.xdata["内存"][i] = this.toDecimal(datas[i].percent)
} }
this.lineChart[data.action] = chartData
},
getTimeFormat(scope) {
return (scope == "rt" || scope == "1h" || scope == "24h") ? "h:i:s" : "m/d h:i:s"
}, },
toMbps(bytes) { toMbps(bytes) {
if (bytes == 0) return 0 if (bytes == 0) return 0