Files
EdgeAdmin/web/views/@default/servers/server/stat/regions.js

86 lines
2.2 KiB
JavaScript
Raw Normal View History

2021-06-08 11:22:44 +08:00
Tea.context(function () {
2021-06-08 15:20:59 +08:00
this.$delay(function () {
let that = this
2021-06-08 11:22:44 +08:00
2021-06-08 15:20:59 +08:00
// 地区
let countryAxis = teaweb.countAxis(this.countryStats, function (v) {
return v.count
})
this.reloadChart("country-chart", "地区", this.countryStats, function (v) {
return v.country.name
}, function (args) {
return that.countryStats[args.dataIndex].country.name + ": " + teaweb.formatNumber(that.countryStats[args.dataIndex].count)
}, countryAxis)
2021-06-08 11:22:44 +08:00
2021-06-08 15:20:59 +08:00
// 省份
let provinceAxis = teaweb.countAxis(this.provinceStats, function (v) {
return v.count
})
this.reloadChart("province-chart", "省市", this.provinceStats, function (v) {
return v.province.name
}, function (args) {
return that.provinceStats[args.dataIndex].country.name + ": " + that.provinceStats[args.dataIndex].province.name + " " + teaweb.formatNumber(that.provinceStats[args.dataIndex].count)
}, provinceAxis)
2021-06-08 11:22:44 +08:00
2021-06-08 15:20:59 +08:00
// 城市
let cityAxis = teaweb.countAxis(this.cityStats, function (v) {
return v.count
})
this.reloadChart("city-chart", "城市", this.cityStats, function (v) {
return v.city.name
}, function (args) {
return that.cityStats[args.dataIndex].country.name + ": " + that.cityStats[args.dataIndex].province.name + " " + that.cityStats[args.dataIndex].city.name + " " + teaweb.formatNumber(that.cityStats[args.dataIndex].count)
}, cityAxis)
})
2021-06-08 11:22:44 +08:00
2021-06-08 15:20:59 +08:00
this.reloadChart = function (chartId, name, stats, xFunc, tooltipFunc, axis) {
let chartBox = document.getElementById(chartId)
if (chartBox == null) {
return
}
2021-07-21 08:07:46 +08:00
let chart = teaweb.initChart(chartBox)
2021-06-08 15:20:59 +08:00
let option = {
xAxis: {
data: stats.map(xFunc),
axisLabel: {
interval: 0
}
},
yAxis: {
axisLabel: {
formatter: function (value) {
return value + axis.unit
}
}
},
tooltip: {
show: true,
trigger: "item",
formatter: tooltipFunc
},
grid: {
left: 40,
top: 10,
right: 20,
bottom: 20
},
series: [
{
name: name,
type: "bar",
data: stats.map(function (v) {
return v.count / axis.divider;
}),
itemStyle: {
2022-04-22 09:58:25 +08:00
color: teaweb.DefaultChartColor
2021-06-08 15:20:59 +08:00
},
barWidth: "20em"
}
],
animation: true
}
chart.setOption(option)
chart.resize()
}
2021-06-08 11:22:44 +08:00
})