From 3304f879939cc851650040c21b5ce8a93140c8c5 Mon Sep 17 00:00:00 2001 From: user Date: Mon, 25 Mar 2024 00:25:17 +0100 Subject: chart switch to bar, tooltip only nonzero, sum --- src/static/histogram.js | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'src/static') diff --git a/src/static/histogram.js b/src/static/histogram.js index 228614c..80048ec 100644 --- a/src/static/histogram.js +++ b/src/static/histogram.js @@ -1,8 +1,16 @@ var ctx = document.getElementById("histogram"); +const footer = (tooltipItems) => { + let sum = 0; + + tooltipItems.forEach(function(tooltipItem) { + sum += tooltipItem.parsed.y; + }); + return 'Sum: ' + sum; +}; var myChart = new Chart(ctx, { - type: "line", + type: "bar", options: { aspectRatio: 4, }, @@ -11,17 +19,36 @@ var myChart = new Chart(ctx, { datasets: datasets }, options: { + interaction: { + intersect: false, + mode: 'index', + }, + plugins: { + tooltip: { + filter: function (tooltipItem, data) { + // Your filtering logic here + console.log(tooltipItem, data); + return tooltipItem.raw != 0; // Show tooltip only for the first dataset + }, + callbacks: { + footer: footer, + }, + }, + }, responsive: true, maintainAspectRatio: false, scales: { + x: { + stacked: true, + }, y: { stacked: true, beginAtZero: true, title: { display: true, text: 'SSH login attempts' - } + }, }, }, layout: { @@ -30,7 +57,7 @@ var myChart = new Chart(ctx, { right: 20, top: 20, bottom: 20 - } + }, } }, }); -- cgit v1.2.3