iwa-panda2

Manage Weather Data by International Weather Agency (Version 2)
Log | Files | Refs | README

commit 7f11e5fd6e991893ed61923fef7facc324b99e3e
parent cec736de0380e21b940fe3cfece2e4ec0525ddf0
Author: Kninteman <[email protected]>
Date:   Mon, 12 Jun 2023 20:34:15 +0200

Facility1&2

Diffstat:
Mjs/panda.js | 24++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/js/panda.js b/js/panda.js @@ -50,15 +50,15 @@ var myChart = new Chart(ctx, { labels: ['Measurement 1', 'Measurement 2', 'Measurement 3', 'Measurement 4', 'Measurement 5'], datasets: [ { - label: 'Chengdu Research Facility', + label: 'Chengdu Research Facility 1', data: [], backgroundColor: 'rgba(176, 204, 207, 1)', borderColor: 'rgba(176, 204, 207, 1)', borderWidth: 2 }, { - label: 'Dataset 2', - data: [6, 7, 8, 9, 10], + label: 'Chengdu Research Facility 2', + data: [], backgroundColor: 'rgba(195, 176, 207, 1)', borderColor: 'rgba(195, 176, 207, 1)', borderWidth: 2 @@ -104,10 +104,26 @@ function fetchDataAndUpdateChart() { data.forEach(point => { array.push(point['humidity']); }); - myChart.data.datasets[0].data = array; + let splitDataResult = splitData(data); + myChart.data.datasets[0].data = splitDataResult.chengduData; + myChart.data.datasets[1].data = splitDataResult.kangdingData; myChart.update(); }) } +function splitData(data) { + let chengduData = []; + let kangdingData = []; + + for (let item of data) { + if (item.location === 'Chengdu') { + chengduData.push(item['humidity']); + } else if (item.location === 'Kangding') { + kangdingData.push(item['humidity']); + } + } + return { chengduData, kangdingData }; +} + fetchDataAndUpdateChart(); setInterval(fetchDataAndUpdateChart, 300000); \ No newline at end of file