Charts & canvas & RGBA
Charts & canvas
RGBA color
let stopFlag = 0;
// show Charts
const showCharts = (name = "") => {
let ctxCPU = document.querySelector(`#cpuChart`).getContext("2d"),
ctxMemory = document.querySelector(`#memoryChart`).getContext("2d");
// Global point options
Chart.defaults.global.elements.point.pointStyle = "circle";
Chart.defaults.global.elements.point.radius = 0;
// init data
// let cpuData = [0.3],
// memoryData = [99.5],
let cpuData = [null],
memoryData = [null],
labels = [" "];
cpuData = repeatArray(cpuData, 60);
memoryData = repeatArray(memoryData, 60);
labels = repeatArray(labels, 60);
let cpuChart = new Chart(ctxCPU, {
// type: "bar ",
type: "line",
data: {
labels: labels,
datasets: [
{
label: "CPU 使用记录",
data: cpuData,
backgroundColor: [
"rgba(241, 246, 250, 0.8)",
],
borderColor: [
"rgba(83, 161, 206, 1)",
],
borderWidth: 1,
fill: "start",
}
]
},
options: {
scales: {
yAxes: [{
ticks: {
// suggestedMax: 1,
suggestedMin: 0.1,
// beginAtZero: true,
callback: function(tick) {
return tick.toString() + "%";
},
}
}]
},
elements: {
line: {
tension: 0,
// no smooth
}
}
}
});
let memoryChart = new Chart(ctxMemory, {
// type: "bar ",
type: "line",
data: {
labels: labels,
datasets: [
{
label: "Memory 使用记录",
data: memoryData,
backgroundColor: [
"rgba(244, 242, 244, 0.8)",
],
borderColor: [
"rgba(164, 73, 190, 1)",// RGBA
// "rgba(0, 127, 53, 1)",// green
// "rgba(149, 40, 180, 1)",
],
borderWidth: 1,
fill: "start",
}
]
},
options: {
scales: {
yAxes: [{
ticks: {
// min: 99,
// max: 100,
// stepSize: 0.000001,
// beginAtZero: false,
// suggestedMax: 100,
callback: function(tick) {
return tick.toString() + "%";
},
}
}]
},
elements: {
line: {
tension: 0,
// no smooth
}
}
}
});
// update
let swalFlag = true;
// console.log(`old stopFlag =`, stopFlag);
stopFlag = setInterval(() => {
showDetails(name).then((json) => {
if (json.success) {
let {
osName,
date,
// totalMemory,
// freeMemory,
cpuRatio,
memoryRatio
} = json.data;
let tds = [...document.querySelectorAll(`[data-info="server"]`)];
for (let i = 0; i < tds.length; i++) {
tds[i].innerHTML = "";
let value = "暂无数据";
switch (i) {
case 0:
value = osName;
break;
case 1:
value = date;
break;
default:
break;
}
tds[i].innerHTML = value;
}
let cpu = cpuRatio,
memory = memoryRatio;
if (cpuData.length > 59) {
cpuData.push(cpu);
let newData = cpu,
oldData = [];
oldData = cpuData.slice(cpuData.length - 59, cpuData.length);
oldData.push(newData);
cpuData = oldData;
// console.log(`cpuData =\n`, cpuData);
cpuChart.data.datasets[0].data = cpuData;
// Preventing Animations
cpuChart.update(0);
} else {
cpuData.push(cpu);
cpuChart.data.datasets[0].data = cpuData;
cpuChart.update(0);
}
if (memoryData.length > 59) {
memoryData.push(memory);
let newData = memory,
oldData = [];
oldData = memoryData.slice(memoryData.length - 59, memoryData.length);
oldData.push(newData);
memoryData = oldData;
memoryChart.data.datasets[0].data = memoryData;
memoryChart.update(0);
} else {
memoryData.push(memory);
memoryChart.data.datasets[0].data = memoryData;
memoryChart.update(0);
}
} else {
if (swalFlag) {
swal({
title: "查看详情失败!",
text: `${json.message !== null ? json.message : "3 秒后自动关闭!"}`,
icon: "error",
// button: "关闭",
buttons: false,
timer: 3000,
});
swalFlag = false;
}
// clear
window.clearInterval(stopFlag);
}
});
}, 1000);
// console.log(`new stopFlag =`, stopFlag);
};
refs
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/9875373.html
未经授权禁止转载,违者必究!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
2015-10-30 Two-factor authentication github2015