diff --git a/frontend/src/components/v-charts/components/Line.vue b/frontend/src/components/v-charts/components/Line.vue
index d28108444..22ee0247d 100644
--- a/frontend/src/components/v-charts/components/Line.vue
+++ b/frontend/src/components/v-charts/components/Line.vue
@@ -31,9 +31,60 @@ const props = defineProps({
option: {
type: Object,
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() {
let itemChart = echarts?.getInstanceByDom(document.getElementById(props.id) as HTMLElement);
// 如果不存在,就进行初始化
@@ -45,44 +96,32 @@ function initChart() {
const series = [];
if (props.option?.yDatas?.length) {
- series.push({
- 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) {
+ props.option?.yDatas.forEach((item: any, index: number) => {
series.push({
- name: props.option?.yDatas[1]?.name,
+ name: item?.name,
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)',
- },
- ]),
- },
- data: props.option?.yDatas[1]?.data,
+ areaStyle: seriesStyle[index],
+ data: item?.data,
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,
z: 1,
- tooltip: {
+ tooltip: props.option.tooltip || {
trigger: 'axis',
formatter: function (datas: any) {
let res = datas[0].name + '
';
@@ -127,7 +166,7 @@ function initChart() {
return res;
},
},
- grid: { left: '7%', right: '7%', bottom: '20%' },
+ grid: props.option.grid || { left: '7%', right: '7%', bottom: '20%' },
legend: {
right: 10,
itemWidth: 8,
@@ -137,26 +176,27 @@ function initChart() {
icon: 'circle',
},
xAxis: { data: props.option.xDatas, boundaryGap: false },
- yAxis: {
- name: '( ' + props.option.formatStr + ' )',
- splitLine: {
- //分隔辅助线
- lineStyle: {
- type: 'dashed', //线的类型 虚线0
- opacity: theme === 'dark' ? 0.1 : 1, //透明度
- },
- },
- },
+ yAxis: props.option.yAxis
+ ? yAxis
+ : {
+ name: '( ' + props.option.formatStr + ' )',
+ splitLine: {
+ //分隔辅助线
+ lineStyle: {
+ type: 'dashed', //线的类型 虚线0
+ opacity: theme === 'dark' ? 0.1 : 1, //透明度
+ },
+ },
+ },
series: series,
dataZoom: [{ startValue: props?.option.xDatas[0], show: props.dataZoom }],
};
// 渲染数据
itemChart.setOption(option, true);
+}
- window.onresize = function () {
- //自适应大小
- itemChart.resize();
- };
+function changeChartSize() {
+ echarts.getInstanceByDom(document.getElementById(props.id) as HTMLElement)?.resize();
}
watch(
@@ -173,11 +213,13 @@ watch(
onMounted(() => {
nextTick(() => {
initChart();
+ window.addEventListener('resize', changeChartSize);
});
});
onBeforeUnmount(() => {
echarts.getInstanceByDom(document.getElementById(props.id) as HTMLElement).dispose();
+ window.removeEventListener('resize', changeChartSize);
});
diff --git a/frontend/src/styles/common.scss b/frontend/src/styles/common.scss
index d28ea73c4..3bebe528a 100644
--- a/frontend/src/styles/common.scss
+++ b/frontend/src/styles/common.scss
@@ -1,3 +1,6 @@
+html {
+ font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, 微软雅黑, Arial, sans-serif;
+}
.flx-center {
display: flex;
align-items: center;
@@ -122,8 +125,6 @@
font-size: 12px;
word-break: break-all;
color: #8f959e;
- transform: scale(0.9);
- transform-origin: left;
width: 110%;
display: inline-block;
}
diff --git a/frontend/src/views/host/monitor/monitor/index.vue b/frontend/src/views/host/monitor/monitor/index.vue
index a7fb46d81..ed3190b14 100644
--- a/frontend/src/views/host/monitor/monitor/index.vue
+++ b/frontend/src/views/host/monitor/monitor/index.vue
@@ -37,12 +37,21 @@
>
-