metrics: show legend with multiple datasets

This commit is contained in:
Girish Ramakrishnan
2025-07-04 12:51:51 +02:00
parent 4caf052199
commit 8bf9d38711
2 changed files with 5 additions and 4 deletions

View File

@@ -32,14 +32,15 @@ const props = defineProps({
cpu: Object,
});
function createGraphOptions({ yscale, period }) {
function createGraphOptions({ yscale, period, displayLegend }) {
const now = Date.now();
return {
maintainAspectRatio: false,
plugins: {
legend: {
display: false
display: displayLegend,
position: 'bottom'
},
tooltip: {
callbacks: {
@@ -202,7 +203,7 @@ function onPeriodChanged() {
}
// this sets a min 'x' based on current timestamp. so it has to re-created every time the period changes
const graphOptions = createGraphOptions({ yscale, period: props.period });
const graphOptions = createGraphOptions({ yscale, period: props.period, displayLegend: props.datasetLabels.length > 1 });
if (!graph) {
graph = new Chart(graphNode.value, { type: 'line', data, options: graphOptions });