From 76d882ef231d44e23d1d201d345a6809f0fef9fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Rynning-T=C3=B8nnesen?= Date: Thu, 30 Jan 2020 16:52:03 +0100 Subject: [PATCH] Dynamic length --- src/ui/PurchaseGraph.vue | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/ui/PurchaseGraph.vue b/src/ui/PurchaseGraph.vue index 5039362..b274446 100644 --- a/src/ui/PurchaseGraph.vue +++ b/src/ui/PurchaseGraph.vue @@ -19,36 +19,44 @@ export default { _response = await fetch("/api/purchase/statistics"); } let response = await _response.json(); - let labels = [""]; + let labels = []; let blue = { label: "Blå", borderColor: "#57d2fb", backgroundColor: "#d4f2fe", borderWidth: 2, - data: [0] + data: [] }; let yellow = { label: "Gul", borderColor: "#ffde5d", backgroundColor: "#fff6d6", borderWidth: 2, - data: [0] + data: [] }; let red = { label: "Rød", borderColor: "#ef5878", backgroundColor: "#fbd7de", borderWidth: 2, - data: [0] + data: [] }; let green = { label: "Grønn", borderColor: "#10e783", backgroundColor: "#c8f9df", borderWidth: 2, - data: [0] + data: [] }; + if (response.length == 1) { + labels.push(""); + blue.data.push(0); + yellow.data.push(0); + red.data.push(0); + green.data.push(0); + } + let highestNumber = 0; for (let i = 0; i < response.length; i++) {