{
"id": "node-chart",
"legendData": ["CPU使用率", "内存使用率", "下载速度KB/s", "上传速度KB/s"],
"xAxisData": [
"2023-07-26 13:45:00", "2023-07-26 13:46:00", "2023-07-26 13:47:00", "2023-07-26 13:48:00", "2023-07-26 13:49:00",
"2023-07-26 13:50:00", "2023-07-26 13:51:00", "2023-07-26 13:52:00", "2023-07-26 13:53:00", "2023-07-26 13:54:00"
],
"series": [{
"name": "CPU使用率",
"data": ["7.38", "7.40", "7.38", "7.42", "8.87", "9.21", "7.46", "7.33", "7.39", "7.44"]
},
{
"name": "内存使用率",
"data": ["85.60", "85.64", "85.61", "85.60", "84.01", "84.13", "84.19", "84.25", "84.30", "84.35"]
},
{
"name": "下载速度KB/s",
"data": ["18249.09", "18141.47", "18111.40", "18100.10", "18189.10", "13774.61", "18109.65", "18223.38", "18139.79", "18131.21"]
},
{
"name": "上传速度KB/s",
"data": ["17894.41", "17805.30", "17766.77", "17808.33", "17826.01", "8770.95", "17769.91", "17885.77", "17800.52", "17793.69"]
}
]
}
let series = [];
let yAxis = [];
let yAxisOne = {
type: 'value',
min: 0,
max: 100,
splitLine: { show: false },
axisLine: { show: true, lineStyle: { color: '#e8e8e8' } },
axisTick: { show: false },
axisLabel: { show: false },
};
if (!props.series.length) {
yAxis.push(yAxisOne);
}
props.series.map((x, i) => {
const copyObj = JSON.parse(JSON.stringify(yAxisOne));
copyObj.min = Math.min(...x.data);
copyObj.max = Math.max(...x.data);
yAxis.push(copyObj);
series.push({
name: x.name,
type: 'line',
data: x.data,
symbol: 'none',
// 多个y轴必须设置
yAxisIndex: i,
});
});
import React from 'react';
import { useEffect } from 'react';
import * as echarts from 'echarts';
export default function (props) {
let series = [];
let yAxis = [];
let yAxisOne = {
type: 'value',
min: 0,
max: 100,
splitLine: { show: false },
axisLine: { show: true, lineStyle: { color: '#e8e8e8' } },
axisTick: { show: false },
axisLabel: { show: false },
};
if (!props.series.length) {
yAxis.push(yAxisOne);
}
props.series.map((x, i) => {
const copyObj = JSON.parse(JSON.stringify(yAxisOne));
copyObj.min = Math.min(...x.data);
copyObj.max = Math.max(...x.data);
yAxis.push(copyObj);
series.push({
name: x.name,
type: 'line',
data: x.data,
symbol: 'none',
// 多个y轴必须设置
yAxisIndex: i,
});
});
useEffect(() => {
const echartsOption = {
title: {
show: false,
},
tooltip: {
trigger: 'axis',
},
legend: {
right: '0.5%',
icon: 'roundRect',
data: props.legendData,
},
grid: {
top: '50%',
left: '0.5%',
right: '0.5%',
bottom: '6%',
containLabel: true,
},
xAxis: {
type: 'category',
boundaryGap: false,
data: props.xAxisData,
splitLine: {
show: false,
},
axisLine: {
show: true,
lineStyle: {
color: '#e8e8e8',
},
},
axisTick: {
show: false,
},
axisLabel: {
show: false,
},
},
yAxis: yAxis,
series: series,
};
let myChart = echarts.getInstanceByDom(document.getElementById(props.id));
if (myChart == null) {
myChart = echarts.init(document.getElementById(props.id));
}
myChart.setOption(echartsOption);
window.addEventListener('resize', function () {
myChart.resize();
});
}, [props.xAxisData]);
return (
<React.Fragment>
<div id={props.id} style={{ width: '100%', height: '100%' }} />
</React.Fragment>
);
}
此页面不支持夜间模式!
已进入夜间模式!
已进入普通模式!
搜索框不允许为空
签到成功!经验+5!芋圆币+2!
签到失败!今日已签到!
需要登录社区账号才可以进入!