Добавил фронтенд
This commit is contained in:
@@ -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.get_statistics = new GetStatistics();
|
||||
window.total_logs_amount = document.getElementById("total-logs-amount");
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
class GetStatistics extends ControllerBase {
|
||||
// Конструктор
|
||||
constructor(url) {
|
||||
super("statistics");
|
||||
|
||||
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() {
|
||||
super.Get({});
|
||||
}
|
||||
|
||||
// Обработка ответа от сервера
|
||||
// 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.get_statistics.SendRequest()
|
||||
}
|
||||
Reference in New Issue
Block a user