Добавил сайт

This commit is contained in:
2024-01-15 03:50:54 +03:00
parent 68e421b336
commit 3f65dd50d3
9 changed files with 355 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
function InitStatisticsChart(labels, colors) {
// Создаём чарт
let chart = new Chart(
document.getElementById("statistics-chart"), {
type: 'pie',
data: {
labels: labels,
datasets: [{
label: "Количество",
data: [0, 0],
backgroundColor: colors
}]
},
options: {
plugins: {
legend: {
display: false
}
}
}
}
);
// Отображаем чарт
chart.update();
return chart;
}
function InitStatistics() {
window.statistics = new Statistics();
window.total_logs_amount = document.getElementById("total-logs-amount");
}
+51
View File
@@ -0,0 +1,51 @@
class Statistics {
// Конструктор
constructor() {
this.labels = [ "Аномальные", "Не аномальные" ];
this.colors = [ "#E96479", "#7DB9B6" ];
this.keys = [ "anomaly", "not anomaly" ];
this.total_amount_key = "total";
this.is_dataset_visible = [true, true];
this.chart = InitStatisticsChart(this.labels, this.colors);
this.context = {
keys: [],
datasets: {}
};
}
// Поля
chart;
context;
// Отправка запроса на сервер
SendRequest() {
var request = {};
request.command = 'statistics';
request.parameters = {};
let request_data = JSON.stringify(request);
socket.send(request_data);
}
// Обработка ответа от сервера
// respone -- ответ сервера
ProcessResponse(response) {
this.UpdateChart(response);
}
// Обновление чарта
// respone -- ответ от сервера
UpdateChart(response) {
let statistics = response["result"];
let statistics_data = [ statistics[this.keys[0]], statistics[this.keys[1]] ];
window.total_logs_amount.innerHTML = "Общее количество: " + statistics[this.total_amount_key];
this.chart.data.datasets[0].data = statistics_data;
this.chart.update();
}
}
function UpdateStatistics() {
window.statistics.SendRequest()
}