From 6e70c792c669fc6c207443af3fecbee6fb6f96bd Mon Sep 17 00:00:00 2001 From: ianmuchyri Date: Fri, 15 Mar 2024 14:13:49 +0300 Subject: [PATCH] update line chart Signed-off-by: ianmuchyri --- ui/web/static/js/charts.js | 154 ++++++++++++-------- ui/web/templates/charts/linechartmodal.html | 17 ++- 2 files changed, 108 insertions(+), 63 deletions(-) diff --git a/ui/web/static/js/charts.js b/ui/web/static/js/charts.js index 2b55ad99..c94657d4 100644 --- a/ui/web/static/js/charts.js +++ b/ui/web/static/js/charts.js @@ -791,6 +791,10 @@ class TimeSeriesLineChart extends Echart { } #generateScript() { + const channels = JSON.stringify(this.chartData.channels); + const things = JSON.stringify(this.chartData.things); + const names = JSON.stringify(this.chartData.valueNames); + const colors = JSON.stringify(this.chartData.colors); return ` var lineChart = echarts.init(document.getElementById("${this.ID}")); var option = { @@ -824,18 +828,17 @@ class TimeSeriesLineChart extends Echart { lineStyle: { width: ${this.chartData.lineWidth}, type: 'solid', - color: '${this.chartData.lineColor}' }, - name: '${this.chartData.seriesName}' } ] }; lineChart.setOption(option); var chartdata = { - channel:'${this.chartData.channel}', - publisher:'${this.chartData.thing}', - name:'${this.chartData.valueName}', + channels:${channels}, + publishers:${things}, + names:${names}, + colors:${colors}, from:${this.chartData.startTime}, to:${this.chartData.stopTime}, aggregation:'${this.chartData.aggregationType}', @@ -846,68 +849,99 @@ class TimeSeriesLineChart extends Echart { async function getData(linechart,chartData) { try { - const response = await fetch( - "${pathPrefix}/data?channel=" + chartData.channel + - "&publisher=" + chartData.publisher + - "&name=" + chartData.name + - "&from=" + chartData.from + - "&to=" + chartData.to + - "&aggregation=" + chartData.aggregation + - "&limit=" + chartData.limit + - "&interval=" + chartData.interval, - ); - if (response.ok) { - const data = await response.json(); - const xAxisArray = []; - const yAxisArray = []; - let currentTimestamp = chartData.from; - let previousTimestamp; - const endTimestamp = chartData.to; - const intervalNum = 3600; - while (currentTimestamp <= endTimestamp) { - let messageIndex = data.messages.length - 1; - let isempty= true; - while (messageIndex >= 0 && (data.messages[messageIndex].time) >= previousTimestamp) { - const item = data.messages[messageIndex]; - if ((item.time) <= currentTimestamp) { - const date = new Date(item.time); - xAxisArray.push(date.toLocaleTimeString()); - yAxisArray.push(item.value); - isempty=false; + let xAxisArray=[]; + const yAxisArray = []; + for (let i=0; i { + const date = new Date(element); + xAxisData.push(date.toLocaleTimeString()); + }) + const seriesData = [] + for (i=0; iData Source const chartData = {}; const channels = []; const things = []; + const names = []; + const colors = []; let formData = new FormData(form); for (let [name, value] of formData) { switch (name) { - case "startTime", "stopTime": + case "startTime": + case "stopTime": const inputDate = new Date(value); chartData[name] = inputDate.getTime(); break; case "channel": - channels.push(pair[1]); + channels.push(value); break; case "thing": - things.push(pair[1]); + things.push(value); + break; + case "valueName": + names.push(value); + break; + case "lineColor": + colors.push(value); break; default: chartData[name] = value; @@ -275,6 +284,8 @@
Data Source
chartData["channels"] = channels; chartData["things"] = things; + chartData["valueNames"]= names; + chartData["colors"]=colors; if (chartData.aggregationType != "") { const updateInterval = form.querySelector("#update-interval");