mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-03-14 01:34:47 +08:00
fix: 优化echart线状图表 (#1673)
#### What this PR does / why we need it? #### Summary of your change #### Please indicate you've done the following: - [ ] Made sure tests are passing and test coverage is added if needed. - [ ] Made sure commit message follow the rule of [Conventional Commits specification](https://www.conventionalcommits.org/). - [ ] Considered the docs impact and opened a new docs issue or PR with docs changes if needed.
This commit is contained in:
parent
15c391e763
commit
e555dcb903
@ -31,9 +31,60 @@ const props = defineProps({
|
|||||||
option: {
|
option: {
|
||||||
type: Object,
|
type: Object,
|
||||||
required: true,
|
required: true,
|
||||||
}, // option: { title , xDatas, yDatas, formatStr }
|
}, // option: { title , xDatas, yDatas, formatStr, yAxis, grid, tooltip}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const seriesStyle = [
|
||||||
|
{
|
||||||
|
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
||||||
|
{
|
||||||
|
offset: 0,
|
||||||
|
color: 'rgba(0, 94, 235, .5)',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
offset: 1,
|
||||||
|
color: 'rgba(0, 94, 235, 0)',
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
||||||
|
{
|
||||||
|
offset: 0,
|
||||||
|
color: 'rgba(27, 143, 60, .5)',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
offset: 1,
|
||||||
|
color: 'rgba(27, 143, 60, 0)',
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
||||||
|
{
|
||||||
|
offset: 0,
|
||||||
|
color: 'rgba(249, 199, 79, .5)',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
offset: 1,
|
||||||
|
color: 'rgba(249, 199, 79, 0)',
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
||||||
|
{
|
||||||
|
offset: 0,
|
||||||
|
color: 'rgba(255, 173, 177, 0.5)',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
offset: 1,
|
||||||
|
color: 'rgba(255, 173, 177, 0)',
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
function initChart() {
|
function initChart() {
|
||||||
let itemChart = echarts?.getInstanceByDom(document.getElementById(props.id) as HTMLElement);
|
let itemChart = echarts?.getInstanceByDom(document.getElementById(props.id) as HTMLElement);
|
||||||
// 如果不存在,就进行初始化
|
// 如果不存在,就进行初始化
|
||||||
@ -45,44 +96,32 @@ function initChart() {
|
|||||||
|
|
||||||
const series = [];
|
const series = [];
|
||||||
if (props.option?.yDatas?.length) {
|
if (props.option?.yDatas?.length) {
|
||||||
series.push({
|
props.option?.yDatas.forEach((item: any, index: number) => {
|
||||||
name: props.option?.yDatas[0]?.name,
|
|
||||||
type: 'line',
|
|
||||||
areaStyle: {
|
|
||||||
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
||||||
{
|
|
||||||
offset: 0,
|
|
||||||
color: 'rgba(0, 94, 235, .5)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
offset: 1,
|
|
||||||
color: 'rgba(0, 94, 235, 0)',
|
|
||||||
},
|
|
||||||
]),
|
|
||||||
},
|
|
||||||
data: props.option?.yDatas[0]?.data,
|
|
||||||
showSymbol: false,
|
|
||||||
});
|
|
||||||
if (props.option?.yDatas?.length > 1) {
|
|
||||||
series.push({
|
series.push({
|
||||||
name: props.option?.yDatas[1]?.name,
|
name: item?.name,
|
||||||
type: 'line',
|
type: 'line',
|
||||||
areaStyle: {
|
areaStyle: seriesStyle[index],
|
||||||
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
data: item?.data,
|
||||||
{
|
|
||||||
offset: 0,
|
|
||||||
color: 'rgba(27, 143, 60, .5)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
offset: 1,
|
|
||||||
color: 'rgba(27, 143, 60, 0)',
|
|
||||||
},
|
|
||||||
]),
|
|
||||||
},
|
|
||||||
data: props.option?.yDatas[1]?.data,
|
|
||||||
showSymbol: false,
|
showSymbol: false,
|
||||||
|
yAxisIndex: item.yAxisIndex ? 1 : null,
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
const yAxis = [];
|
||||||
|
if (props.option.yAxis && props.option.yAxis.length > 0) {
|
||||||
|
props.option.yAxis.forEach((item: any) => {
|
||||||
|
yAxis.push({
|
||||||
|
splitLine: {
|
||||||
|
show: true,
|
||||||
|
//分隔辅助线
|
||||||
|
lineStyle: {
|
||||||
|
type: 'dashed', //线的类型 虚线0
|
||||||
|
opacity: theme === 'dark' ? 0.1 : 1, //透明度
|
||||||
|
},
|
||||||
|
},
|
||||||
|
...item,
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 把配置和数据放这里
|
// 把配置和数据放这里
|
||||||
@ -96,7 +135,7 @@ function initChart() {
|
|||||||
],
|
],
|
||||||
zlevel: 1,
|
zlevel: 1,
|
||||||
z: 1,
|
z: 1,
|
||||||
tooltip: {
|
tooltip: props.option.tooltip || {
|
||||||
trigger: 'axis',
|
trigger: 'axis',
|
||||||
formatter: function (datas: any) {
|
formatter: function (datas: any) {
|
||||||
let res = datas[0].name + '<br/>';
|
let res = datas[0].name + '<br/>';
|
||||||
@ -127,7 +166,7 @@ function initChart() {
|
|||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
grid: { left: '7%', right: '7%', bottom: '20%' },
|
grid: props.option.grid || { left: '7%', right: '7%', bottom: '20%' },
|
||||||
legend: {
|
legend: {
|
||||||
right: 10,
|
right: 10,
|
||||||
itemWidth: 8,
|
itemWidth: 8,
|
||||||
@ -137,26 +176,27 @@ function initChart() {
|
|||||||
icon: 'circle',
|
icon: 'circle',
|
||||||
},
|
},
|
||||||
xAxis: { data: props.option.xDatas, boundaryGap: false },
|
xAxis: { data: props.option.xDatas, boundaryGap: false },
|
||||||
yAxis: {
|
yAxis: props.option.yAxis
|
||||||
name: '( ' + props.option.formatStr + ' )',
|
? yAxis
|
||||||
splitLine: {
|
: {
|
||||||
//分隔辅助线
|
name: '( ' + props.option.formatStr + ' )',
|
||||||
lineStyle: {
|
splitLine: {
|
||||||
type: 'dashed', //线的类型 虚线0
|
//分隔辅助线
|
||||||
opacity: theme === 'dark' ? 0.1 : 1, //透明度
|
lineStyle: {
|
||||||
},
|
type: 'dashed', //线的类型 虚线0
|
||||||
},
|
opacity: theme === 'dark' ? 0.1 : 1, //透明度
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
series: series,
|
series: series,
|
||||||
dataZoom: [{ startValue: props?.option.xDatas[0], show: props.dataZoom }],
|
dataZoom: [{ startValue: props?.option.xDatas[0], show: props.dataZoom }],
|
||||||
};
|
};
|
||||||
// 渲染数据
|
// 渲染数据
|
||||||
itemChart.setOption(option, true);
|
itemChart.setOption(option, true);
|
||||||
|
}
|
||||||
|
|
||||||
window.onresize = function () {
|
function changeChartSize() {
|
||||||
//自适应大小
|
echarts.getInstanceByDom(document.getElementById(props.id) as HTMLElement)?.resize();
|
||||||
itemChart.resize();
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
@ -173,11 +213,13 @@ watch(
|
|||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
initChart();
|
initChart();
|
||||||
|
window.addEventListener('resize', changeChartSize);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
echarts.getInstanceByDom(document.getElementById(props.id) as HTMLElement).dispose();
|
echarts.getInstanceByDom(document.getElementById(props.id) as HTMLElement).dispose();
|
||||||
|
window.removeEventListener('resize', changeChartSize);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scoped></style>
|
<style lang="scss" scoped></style>
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
html {
|
||||||
|
font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, 微软雅黑, Arial, sans-serif;
|
||||||
|
}
|
||||||
.flx-center {
|
.flx-center {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@ -122,8 +125,6 @@
|
|||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
word-break: break-all;
|
word-break: break-all;
|
||||||
color: #8f959e;
|
color: #8f959e;
|
||||||
transform: scale(0.9);
|
|
||||||
transform-origin: left;
|
|
||||||
width: 110%;
|
width: 110%;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
@ -37,12 +37,21 @@
|
|||||||
></el-date-picker>
|
></el-date-picker>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<div id="loadLoadChart" class="chart"></div>
|
<div class="chart">
|
||||||
|
<v-charts
|
||||||
|
height="400px"
|
||||||
|
id="loadLoadChart"
|
||||||
|
type="line"
|
||||||
|
:option="chartsOption['loadLoadChart']"
|
||||||
|
v-if="chartsOption['loadLoadChart']"
|
||||||
|
:dataZoom="true"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</el-card>
|
</el-card>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
<el-row :gutter="20" style="margin-top: 20px">
|
<el-row :gutter="20" style="margin-top: 20px">
|
||||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
|
<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
|
||||||
<el-card style="overflow: inherit">
|
<el-card style="overflow: inherit">
|
||||||
<template #header>
|
<template #header>
|
||||||
<div :class="mobile ? 'flx-wrap' : 'flx-justify-between'">
|
<div :class="mobile ? 'flx-wrap' : 'flx-justify-between'">
|
||||||
@ -60,10 +69,19 @@
|
|||||||
></el-date-picker>
|
></el-date-picker>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<div id="loadCPUChart" class="chart"></div>
|
<div class="chart">
|
||||||
|
<v-charts
|
||||||
|
height="400px"
|
||||||
|
id="loadCPUChart"
|
||||||
|
type="line"
|
||||||
|
:option="chartsOption['loadCPUChart']"
|
||||||
|
v-if="chartsOption['loadCPUChart']"
|
||||||
|
:dataZoom="true"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</el-card>
|
</el-card>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
|
<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
|
||||||
<el-card style="overflow: inherit">
|
<el-card style="overflow: inherit">
|
||||||
<template #header>
|
<template #header>
|
||||||
<div :class="mobile ? 'flx-wrap' : 'flx-justify-between'">
|
<div :class="mobile ? 'flx-wrap' : 'flx-justify-between'">
|
||||||
@ -81,12 +99,21 @@
|
|||||||
></el-date-picker>
|
></el-date-picker>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<div id="loadMemoryChart" class="chart"></div>
|
<div class="chart">
|
||||||
|
<v-charts
|
||||||
|
height="400px"
|
||||||
|
id="loadMemoryChart"
|
||||||
|
type="line"
|
||||||
|
:option="chartsOption['loadMemoryChart']"
|
||||||
|
v-if="chartsOption['loadMemoryChart']"
|
||||||
|
:dataZoom="true"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</el-card>
|
</el-card>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
<el-row :gutter="20" style="margin-top: 20px">
|
<el-row :gutter="20" style="margin-top: 20px">
|
||||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
|
<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
|
||||||
<el-card style="overflow: inherit">
|
<el-card style="overflow: inherit">
|
||||||
<template #header>
|
<template #header>
|
||||||
<div :class="mobile ? 'flx-wrap' : 'flx-justify-between'">
|
<div :class="mobile ? 'flx-wrap' : 'flx-justify-between'">
|
||||||
@ -104,10 +131,19 @@
|
|||||||
></el-date-picker>
|
></el-date-picker>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<div id="loadIOChart" class="chart"></div>
|
<div class="chart">
|
||||||
|
<v-charts
|
||||||
|
height="400px"
|
||||||
|
id="loadIOChart"
|
||||||
|
type="line"
|
||||||
|
:option="chartsOption['loadIOChart']"
|
||||||
|
v-if="chartsOption['loadIOChart']"
|
||||||
|
:dataZoom="true"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</el-card>
|
</el-card>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
|
<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
|
||||||
<el-card style="overflow: inherit">
|
<el-card style="overflow: inherit">
|
||||||
<template #header>
|
<template #header>
|
||||||
<div :class="mobile ? 'flx-wrap' : 'flx-justify-between'">
|
<div :class="mobile ? 'flx-wrap' : 'flx-justify-between'">
|
||||||
@ -148,7 +184,16 @@
|
|||||||
></el-date-picker>
|
></el-date-picker>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<div id="loadNetworkChart" class="chart"></div>
|
<div class="chart">
|
||||||
|
<v-charts
|
||||||
|
height="400px"
|
||||||
|
id="loadNetworkChart"
|
||||||
|
type="line"
|
||||||
|
:option="chartsOption['loadNetworkChart']"
|
||||||
|
v-if="chartsOption['loadNetworkChart']"
|
||||||
|
:dataZoom="true"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</el-card>
|
</el-card>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
@ -156,8 +201,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, reactive, onMounted, onBeforeUnmount, computed } from 'vue';
|
import { ref, reactive, onMounted, computed } from 'vue';
|
||||||
import * as echarts from 'echarts';
|
|
||||||
import { loadMonitor, getNetworkOptions } from '@/api/modules/monitor';
|
import { loadMonitor, getNetworkOptions } from '@/api/modules/monitor';
|
||||||
import { Monitor } from '@/api/interface/monitor';
|
import { Monitor } from '@/api/interface/monitor';
|
||||||
import { computeSizeFromKBs, dateFormatWithoutYear } from '@/utils/util';
|
import { computeSizeFromKBs, dateFormatWithoutYear } from '@/utils/util';
|
||||||
@ -181,6 +225,8 @@ const timeRangeIO = ref<[Date, Date]>([new Date(new Date().setHours(0, 0, 0, 0))
|
|||||||
const timeRangeNetwork = ref<[Date, Date]>([new Date(new Date().setHours(0, 0, 0, 0)), new Date()]);
|
const timeRangeNetwork = ref<[Date, Date]>([new Date(new Date().setHours(0, 0, 0, 0)), new Date()]);
|
||||||
const networkChoose = ref();
|
const networkChoose = ref();
|
||||||
const netOptions = ref();
|
const netOptions = ref();
|
||||||
|
const chartsOption = ref({ loadLoadChart: null, loadCPUChart: null, loadMemoryChart: null, loadNetworkChart: null });
|
||||||
|
|
||||||
const shortcuts = [
|
const shortcuts = [
|
||||||
{
|
{
|
||||||
text: i18n.global.t('monitor.today'),
|
text: i18n.global.t('monitor.today'),
|
||||||
@ -287,50 +333,34 @@ const search = async (param: string) => {
|
|||||||
return item.cpu.toFixed(2);
|
return item.cpu.toFixed(2);
|
||||||
});
|
});
|
||||||
cpuData = cpuData.length === 0 ? loadEmptyData() : cpuData;
|
cpuData = cpuData.length === 0 ? loadEmptyData() : cpuData;
|
||||||
let yDatasOfCpu = {
|
chartsOption.value['loadCPUChart'] = {
|
||||||
name: 'CPU',
|
xDatas: baseDate,
|
||||||
type: 'line',
|
yDatas: [
|
||||||
areaStyle: {
|
{
|
||||||
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
name: 'CPU',
|
||||||
{
|
data: cpuData,
|
||||||
offset: 0,
|
},
|
||||||
color: 'rgba(0, 94, 235, .5)',
|
],
|
||||||
},
|
|
||||||
{
|
formatStr: '%',
|
||||||
offset: 1,
|
|
||||||
color: 'rgba(0, 94, 235, 0)',
|
|
||||||
},
|
|
||||||
]),
|
|
||||||
},
|
|
||||||
data: cpuData,
|
|
||||||
showSymbol: false,
|
|
||||||
};
|
};
|
||||||
initCharts('loadCPUChart', baseDate, yDatasOfCpu, 'CPU', '%');
|
|
||||||
}
|
}
|
||||||
if (param === 'memory' || param === 'all') {
|
if (param === 'memory' || param === 'all') {
|
||||||
let memoryData = item.value.map(function (item: any) {
|
let memoryData = item.value.map(function (item: any) {
|
||||||
return item.memory.toFixed(2);
|
return item.memory.toFixed(2);
|
||||||
});
|
});
|
||||||
memoryData = memoryData.length === 0 ? loadEmptyData() : memoryData;
|
memoryData = memoryData.length === 0 ? loadEmptyData() : memoryData;
|
||||||
let yDatasOfMem = {
|
chartsOption.value['loadMemoryChart'] = {
|
||||||
name: i18n.global.t('monitor.memory'),
|
xDatas: baseDate,
|
||||||
type: 'line',
|
yDatas: [
|
||||||
areaStyle: {
|
{
|
||||||
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
name: i18n.global.t('monitor.memory'),
|
||||||
{
|
data: memoryData,
|
||||||
offset: 0,
|
},
|
||||||
color: 'rgba(0, 94, 235, .5)',
|
],
|
||||||
},
|
|
||||||
{
|
formatStr: '%',
|
||||||
offset: 1,
|
|
||||||
color: 'rgba(0, 94, 235, 0)',
|
|
||||||
},
|
|
||||||
]),
|
|
||||||
},
|
|
||||||
data: memoryData,
|
|
||||||
showSymbol: false,
|
|
||||||
};
|
};
|
||||||
initCharts('loadMemoryChart', baseDate, yDatasOfMem, i18n.global.t('monitor.memory'), '%');
|
|
||||||
}
|
}
|
||||||
if (param === 'load' || param === 'all') {
|
if (param === 'load' || param === 'all') {
|
||||||
initLoadCharts(item);
|
initLoadCharts(item);
|
||||||
@ -348,47 +378,30 @@ const search = async (param: string) => {
|
|||||||
return item.up.toFixed(2);
|
return item.up.toFixed(2);
|
||||||
});
|
});
|
||||||
networkUp = networkUp.length === 0 ? loadEmptyData() : networkUp;
|
networkUp = networkUp.length === 0 ? loadEmptyData() : networkUp;
|
||||||
let yDatasOfUp = {
|
|
||||||
name: i18n.global.t('monitor.up'),
|
|
||||||
type: 'line',
|
|
||||||
areaStyle: {
|
|
||||||
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
||||||
{
|
|
||||||
offset: 0,
|
|
||||||
color: 'rgba(0, 94, 235, .5)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
offset: 1,
|
|
||||||
color: 'rgba(0, 94, 235, 0)',
|
|
||||||
},
|
|
||||||
]),
|
|
||||||
},
|
|
||||||
data: networkUp,
|
|
||||||
showSymbol: false,
|
|
||||||
};
|
|
||||||
let networkOut = item.value.map(function (item: any) {
|
let networkOut = item.value.map(function (item: any) {
|
||||||
return item.down.toFixed(2);
|
return item.down.toFixed(2);
|
||||||
});
|
});
|
||||||
networkOut = networkOut.length === 0 ? loadEmptyData() : networkOut;
|
networkOut = networkOut.length === 0 ? loadEmptyData() : networkOut;
|
||||||
let yDatasOfDown = {
|
|
||||||
name: i18n.global.t('monitor.down'),
|
chartsOption.value['loadNetworkChart'] = {
|
||||||
type: 'line',
|
xDatas: networkDate,
|
||||||
areaStyle: {
|
yDatas: [
|
||||||
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
{
|
||||||
{
|
name: i18n.global.t('monitor.up'),
|
||||||
offset: 0,
|
data: networkUp,
|
||||||
color: 'rgba(27, 143, 60, .5)',
|
},
|
||||||
},
|
{
|
||||||
{
|
name: i18n.global.t('monitor.down'),
|
||||||
offset: 1,
|
data: networkOut,
|
||||||
color: 'rgba(27, 143, 60, 0)',
|
},
|
||||||
},
|
],
|
||||||
]),
|
grid: {
|
||||||
|
left: getSideWidth(true),
|
||||||
|
right: getSideWidth(true),
|
||||||
|
bottom: '20%',
|
||||||
},
|
},
|
||||||
data: networkOut,
|
formatStr: 'KB/s',
|
||||||
showSymbol: false,
|
|
||||||
};
|
};
|
||||||
initCharts('loadNetworkChart', networkDate, [yDatasOfUp, yDatasOfDown], 'KB/s', 'KB/s');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -401,47 +414,6 @@ const loadNetworkOptions = async () => {
|
|||||||
search('all');
|
search('all');
|
||||||
};
|
};
|
||||||
|
|
||||||
function initCharts(chartName: string, xDatas: any, yDatas: any, yTitle: string, formatStr: string) {
|
|
||||||
const lineChart = echarts.init(document.getElementById(chartName) as HTMLElement);
|
|
||||||
const option = {
|
|
||||||
zlevel: 1,
|
|
||||||
z: 1,
|
|
||||||
tooltip: {
|
|
||||||
trigger: 'axis',
|
|
||||||
formatter: function (datas: any) {
|
|
||||||
let res = datas[0].name + '<br/>';
|
|
||||||
if (chartName !== 'loadNetworkChart') {
|
|
||||||
for (const item of datas) {
|
|
||||||
res += item.marker + ' ' + item.seriesName + ':' + item.data + formatStr + '<br/>';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (const item of datas) {
|
|
||||||
res += item.marker + ' ' + item.seriesName + ':' + computeSizeFromKBs(item.data) + '<br/>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
legend: {
|
|
||||||
data: chartName === 'loadNetworkChart' && [i18n.global.t('monitor.up'), i18n.global.t('monitor.down')],
|
|
||||||
textStyle: {
|
|
||||||
color: '#646A73',
|
|
||||||
},
|
|
||||||
icon: 'circle',
|
|
||||||
},
|
|
||||||
grid: {
|
|
||||||
left: getSideWidth(chartName == 'loadNetworkChart'),
|
|
||||||
right: getSideWidth(chartName == 'loadNetworkChart'),
|
|
||||||
bottom: '20%',
|
|
||||||
},
|
|
||||||
xAxis: { data: xDatas },
|
|
||||||
yAxis: { name: '( ' + formatStr + ' )', axisLabel: { fontSize: chartName == 'loadNetworkChart' ? 10 : 12 } },
|
|
||||||
dataZoom: [{ startValue: zoomStart.value }],
|
|
||||||
series: yDatas,
|
|
||||||
};
|
|
||||||
lineChart.setOption(option, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function initLoadCharts(item: Monitor.MonitorData) {
|
function initLoadCharts(item: Monitor.MonitorData) {
|
||||||
let itemLoadDate = item.date.length === 0 ? loadEmptyDate(timeRangeLoad.value) : item.date;
|
let itemLoadDate = item.date.length === 0 ? loadEmptyDate(timeRangeLoad.value) : item.date;
|
||||||
let loadDate = itemLoadDate.map(function (item: any) {
|
let loadDate = itemLoadDate.map(function (item: any) {
|
||||||
@ -463,37 +435,27 @@ function initLoadCharts(item: Monitor.MonitorData) {
|
|||||||
return item.loadUsage.toFixed(2);
|
return item.loadUsage.toFixed(2);
|
||||||
});
|
});
|
||||||
loadUsage = loadUsage.length === 0 ? loadEmptyData() : loadUsage;
|
loadUsage = loadUsage.length === 0 ? loadEmptyData() : loadUsage;
|
||||||
|
chartsOption.value['loadLoadChart'] = {
|
||||||
const lineChart = echarts.init(document.getElementById('loadLoadChart') as HTMLElement);
|
xDatas: loadDate,
|
||||||
const option = {
|
yDatas: [
|
||||||
zlevel: 1,
|
{
|
||||||
z: 1,
|
name: '1 ' + i18n.global.t('commons.units.minute'),
|
||||||
tooltip: {
|
data: load1Data,
|
||||||
trigger: 'axis',
|
|
||||||
formatter: function (datas: any) {
|
|
||||||
let res = datas[0].name + '<br/>';
|
|
||||||
for (const item of datas) {
|
|
||||||
res += item.marker + ' ' + item.seriesName + ':' + item.data + '%' + '<br/>';
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
},
|
},
|
||||||
},
|
{
|
||||||
legend: {
|
name: '5 ' + i18n.global.t('commons.units.minute'),
|
||||||
data: [
|
data: load5Data,
|
||||||
'1 ' + i18n.global.t('commons.units.minute'),
|
|
||||||
'5 ' + i18n.global.t('commons.units.minute'),
|
|
||||||
'15 ' + i18n.global.t('commons.units.minute'),
|
|
||||||
i18n.global.t('monitor.resourceUsage'),
|
|
||||||
],
|
|
||||||
textStyle: {
|
|
||||||
color: '#646A73',
|
|
||||||
},
|
},
|
||||||
icon: 'circle',
|
{
|
||||||
},
|
name: '15 ' + i18n.global.t('commons.units.minute'),
|
||||||
grid: { left: '7%', right: '7%', bottom: '20%' },
|
data: load15Data,
|
||||||
xAxis: {
|
},
|
||||||
data: loadDate,
|
{
|
||||||
},
|
name: i18n.global.t('monitor.resourceUsage'),
|
||||||
|
data: loadUsage,
|
||||||
|
yAxisIndex: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
yAxis: [
|
yAxis: [
|
||||||
{ type: 'value', name: i18n.global.t('monitor.loadDetail') + ' ( % )' },
|
{ type: 'value', name: i18n.global.t('monitor.loadDetail') + ' ( % )' },
|
||||||
{
|
{
|
||||||
@ -503,84 +465,8 @@ function initLoadCharts(item: Monitor.MonitorData) {
|
|||||||
alignTicks: true,
|
alignTicks: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
dataZoom: [{ startValue: zoomStart.value }],
|
formatStr: '%',
|
||||||
series: [
|
|
||||||
{
|
|
||||||
name: '1 ' + i18n.global.t('commons.units.minute'),
|
|
||||||
type: 'line',
|
|
||||||
areaStyle: {
|
|
||||||
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
||||||
{
|
|
||||||
offset: 0,
|
|
||||||
color: 'rgba(0, 94, 235, .5)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
offset: 1,
|
|
||||||
color: 'rgba(0, 94, 235, 0)',
|
|
||||||
},
|
|
||||||
]),
|
|
||||||
},
|
|
||||||
showSymbol: false,
|
|
||||||
data: load1Data,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: '5 ' + i18n.global.t('commons.units.minute'),
|
|
||||||
type: 'line',
|
|
||||||
areaStyle: {
|
|
||||||
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
||||||
{
|
|
||||||
offset: 0,
|
|
||||||
color: 'rgba(27, 143, 60, .5)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
offset: 1,
|
|
||||||
color: 'rgba(27, 143, 60, 0)',
|
|
||||||
},
|
|
||||||
]),
|
|
||||||
},
|
|
||||||
showSymbol: false,
|
|
||||||
data: load5Data,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: '15 ' + i18n.global.t('commons.units.minute'),
|
|
||||||
type: 'line',
|
|
||||||
areaStyle: {
|
|
||||||
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
||||||
{
|
|
||||||
offset: 0,
|
|
||||||
color: 'rgba(249, 199, 79, .5)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
offset: 1,
|
|
||||||
color: 'rgba(249, 199, 79, 0)',
|
|
||||||
},
|
|
||||||
]),
|
|
||||||
},
|
|
||||||
showSymbol: false,
|
|
||||||
data: load15Data,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: i18n.global.t('monitor.resourceUsage'),
|
|
||||||
type: 'line',
|
|
||||||
areaStyle: {
|
|
||||||
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
||||||
{
|
|
||||||
offset: 0,
|
|
||||||
color: 'rgba(255, 173, 177, 0.5)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
offset: 1,
|
|
||||||
color: 'rgba(255, 173, 177, 0)',
|
|
||||||
},
|
|
||||||
]),
|
|
||||||
},
|
|
||||||
showSymbol: false,
|
|
||||||
data: loadUsage,
|
|
||||||
yAxisIndex: 1,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
lineChart.setOption(option, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function initIOCharts(item: Monitor.MonitorData) {
|
function initIOCharts(item: Monitor.MonitorData) {
|
||||||
@ -604,11 +490,28 @@ function initIOCharts(item: Monitor.MonitorData) {
|
|||||||
return item.time;
|
return item.time;
|
||||||
});
|
});
|
||||||
ioTime = ioTime.length === 0 ? loadEmptyData() : ioTime;
|
ioTime = ioTime.length === 0 ? loadEmptyData() : ioTime;
|
||||||
|
chartsOption.value['loadIOChart'] = {
|
||||||
const lineChart = echarts.init(document.getElementById('loadIOChart') as HTMLElement);
|
xDatas: ioDate,
|
||||||
const option = {
|
yDatas: [
|
||||||
zlevel: 1,
|
{
|
||||||
z: 1,
|
name: i18n.global.t('monitor.read'),
|
||||||
|
data: ioRead,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: i18n.global.t('monitor.write'),
|
||||||
|
data: ioWrite,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: i18n.global.t('monitor.readWriteCount'),
|
||||||
|
data: ioCount,
|
||||||
|
yAxisIndex: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: i18n.global.t('monitor.readWriteTime'),
|
||||||
|
data: ioTime,
|
||||||
|
yAxisIndex: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
tooltip: {
|
tooltip: {
|
||||||
trigger: 'axis',
|
trigger: 'axis',
|
||||||
formatter: function (datas: any) {
|
formatter: function (datas: any) {
|
||||||
@ -639,22 +542,7 @@ function initIOCharts(item: Monitor.MonitorData) {
|
|||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
legend: {
|
|
||||||
data: [
|
|
||||||
i18n.global.t('monitor.read'),
|
|
||||||
i18n.global.t('monitor.write'),
|
|
||||||
i18n.global.t('monitor.readWriteCount'),
|
|
||||||
i18n.global.t('monitor.readWriteTime'),
|
|
||||||
],
|
|
||||||
textStyle: {
|
|
||||||
color: '#646A73',
|
|
||||||
},
|
|
||||||
icon: 'circle',
|
|
||||||
},
|
|
||||||
grid: { left: getSideWidth(true), right: getSideWidth(true), bottom: '20%' },
|
grid: { left: getSideWidth(true), right: getSideWidth(true), bottom: '20%' },
|
||||||
xAxis: {
|
|
||||||
data: ioDate,
|
|
||||||
},
|
|
||||||
yAxis: [
|
yAxis: [
|
||||||
{ type: 'value', name: '( KB/s )', axisLabel: { fontSize: 10 } },
|
{ type: 'value', name: '( KB/s )', axisLabel: { fontSize: 10 } },
|
||||||
{
|
{
|
||||||
@ -666,85 +554,7 @@ function initIOCharts(item: Monitor.MonitorData) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
dataZoom: [{ startValue: zoomStart.value }],
|
|
||||||
series: [
|
|
||||||
{
|
|
||||||
name: i18n.global.t('monitor.read'),
|
|
||||||
type: 'line',
|
|
||||||
areaStyle: {
|
|
||||||
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
||||||
{
|
|
||||||
offset: 0,
|
|
||||||
color: 'rgba(0, 94, 235, .5)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
offset: 1,
|
|
||||||
color: 'rgba(0, 94, 235, 0)',
|
|
||||||
},
|
|
||||||
]),
|
|
||||||
},
|
|
||||||
showSymbol: false,
|
|
||||||
data: ioRead,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: i18n.global.t('monitor.write'),
|
|
||||||
type: 'line',
|
|
||||||
areaStyle: {
|
|
||||||
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
||||||
{
|
|
||||||
offset: 0,
|
|
||||||
color: 'rgba(27, 143, 60, .5)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
offset: 1,
|
|
||||||
color: 'rgba(27, 143, 60, 0)',
|
|
||||||
},
|
|
||||||
]),
|
|
||||||
},
|
|
||||||
showSymbol: false,
|
|
||||||
data: ioWrite,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: i18n.global.t('monitor.readWriteCount'),
|
|
||||||
type: 'line',
|
|
||||||
areaStyle: {
|
|
||||||
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
||||||
{
|
|
||||||
offset: 0,
|
|
||||||
color: 'rgba(249, 199, 79, .5)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
offset: 1,
|
|
||||||
color: 'rgba(249, 199, 79, 0)',
|
|
||||||
},
|
|
||||||
]),
|
|
||||||
},
|
|
||||||
showSymbol: false,
|
|
||||||
data: ioCount,
|
|
||||||
yAxisIndex: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: i18n.global.t('monitor.readWriteTime'),
|
|
||||||
type: 'line',
|
|
||||||
areaStyle: {
|
|
||||||
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
||||||
{
|
|
||||||
offset: 0,
|
|
||||||
color: 'rgba(255, 173, 177, 0.5)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
offset: 1,
|
|
||||||
color: 'rgba(255, 173, 177, 0)',
|
|
||||||
},
|
|
||||||
]),
|
|
||||||
},
|
|
||||||
showSymbol: false,
|
|
||||||
data: ioTime,
|
|
||||||
yAxisIndex: 1,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
lineChart.setOption(option, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadEmptyDate(timeRange: any) {
|
function loadEmptyDate(timeRange: any) {
|
||||||
@ -763,30 +573,9 @@ function getSideWidth(b: boolean) {
|
|||||||
return !b || document.body.clientWidth > 1600 ? '7%' : '10%';
|
return !b || document.body.clientWidth > 1600 ? '7%' : '10%';
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeChartSize() {
|
|
||||||
echarts.getInstanceByDom(document.getElementById('loadLoadChart') as HTMLElement)?.resize();
|
|
||||||
echarts.getInstanceByDom(document.getElementById('loadCPUChart') as HTMLElement)?.resize();
|
|
||||||
echarts.getInstanceByDom(document.getElementById('loadMemoryChart') as HTMLElement)?.resize();
|
|
||||||
echarts.getInstanceByDom(document.getElementById('loadIOChart') as HTMLElement)?.resize();
|
|
||||||
echarts.getInstanceByDom(document.getElementById('loadNetworkChart') as HTMLElement)?.resize();
|
|
||||||
}
|
|
||||||
|
|
||||||
function disposeChart() {
|
|
||||||
echarts.getInstanceByDom(document.getElementById('loadLoadChart') as HTMLElement)?.dispose();
|
|
||||||
echarts.getInstanceByDom(document.getElementById('loadCPUChart') as HTMLElement)?.dispose();
|
|
||||||
echarts.getInstanceByDom(document.getElementById('loadMemoryChart') as HTMLElement)?.dispose();
|
|
||||||
echarts.getInstanceByDom(document.getElementById('loadIOChart') as HTMLElement)?.dispose();
|
|
||||||
echarts.getInstanceByDom(document.getElementById('loadNetworkChart') as HTMLElement)?.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
zoomStart.value = dateFormatWithoutYear(new Date(new Date().setHours(0, 0, 0, 0)));
|
zoomStart.value = dateFormatWithoutYear(new Date(new Date().setHours(0, 0, 0, 0)));
|
||||||
loadNetworkOptions();
|
loadNetworkOptions();
|
||||||
window.addEventListener('resize', changeChartSize);
|
|
||||||
});
|
|
||||||
onBeforeUnmount(() => {
|
|
||||||
disposeChart();
|
|
||||||
window.removeEventListener('resize', changeChartSize);
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user