From f6ff95dcb2d03180c0f52295c09848c8f563e69f Mon Sep 17 00:00:00 2001 From: Musilah Date: Tue, 19 Mar 2024 18:34:58 +0300 Subject: [PATCH] add colour option Signed-off-by: Musilah --- ui/web/static/js/charts.js | 10 +++++++-- ui/web/templates/charts/multigaugemodal.html | 22 +++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/ui/web/static/js/charts.js b/ui/web/static/js/charts.js index a2af4595..8ef2d98a 100644 --- a/ui/web/static/js/charts.js +++ b/ui/web/static/js/charts.js @@ -1132,11 +1132,13 @@ class MultiGaugeChart extends Echart { const channels = JSON.stringify(this.chartData.channels); const things = JSON.stringify(this.chartData.things); const gaugeLabel = this.chartData.labels; + const colours = this.chartData.colours; return ` var multiGaugeChart = echarts.init(document.getElementById("${this.ID}")); - gaugeLabel = ${JSON.stringify(gaugeLabel)}; + var gaugeLabel = ${JSON.stringify(gaugeLabel)}; + var colours = ${JSON.stringify(colours)}; var gaugeData = gaugeLabel.map((label, index) => { // Dynamic positioning can be improved based on the number of gauges @@ -1214,7 +1216,8 @@ class MultiGaugeChart extends Echart { channels: ${channels}, publishers: ${things}, gaugeLabel: gaugeLabel, - name: '${this.chartData.valueName}' + name: '${this.chartData.valueName}', + colours: colours, } getData(multiGaugeChart, chartData); @@ -1248,6 +1251,9 @@ class MultiGaugeChart extends Echart { detail: { valueAnimation: true, offsetCenter: ['0%', (index - (gaugeLabel.length - 1) / 2) * 40 + 12 + '%'] + }, + itemStyle: { + color: chartData.colours[i], } }; }); diff --git a/ui/web/templates/charts/multigaugemodal.html b/ui/web/templates/charts/multigaugemodal.html index 625a1e63..d3162593 100644 --- a/ui/web/templates/charts/multigaugemodal.html +++ b/ui/web/templates/charts/multigaugemodal.html @@ -72,6 +72,7 @@
Data Source
Channel Thing Label + Colour @@ -107,7 +108,18 @@
Data Source
/> - @@ -213,6 +225,7 @@
Data Source
const channels = []; const things = []; const labels = []; + const colours = []; let formData = new FormData(form); for (let [name, value] of formData) { switch (name) { @@ -225,6 +238,9 @@
Data Source
case "gaugeLabel": labels.push(value); break; + case "gaugeColour": + colours.push(value); + break; default: chartData[name] = value; break; @@ -233,6 +249,7 @@
Data Source
chartData["channels"] = channels; chartData["things"] = things; chartData["labels"] = labels; + chartData["colours"] = colours; var widgetID = "multiGaugeChart-" + Date.now(); @@ -269,6 +286,9 @@
Data Source
+ + +