Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
iCity
EnergyDashboard
Commits
82d3c47d
Commit
82d3c47d
authored
3 years ago
by
Pithon Kabiro
Browse files
Options
Download
Email Patches
Plain Diff
Add line chart / Highcharts
parent
afecef1a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
index.html
+3
-1
index.html
public/js/appChart.js
+49
-0
public/js/appChart.js
with
52 additions
and
1 deletion
+52
-1
index.html
+
3
-
1
View file @
82d3c47d
...
@@ -28,7 +28,9 @@
...
@@ -28,7 +28,9 @@
<script
src=
"https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"
></script>
<script
src=
"https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"
></script>
<!-- Higcharts lib -->
<!-- Higcharts lib -->
<script
src=
"https://code.highcharts.com/highcharts.js"
></script>
<!-- Does not play well with `Highstock`; see: https://www.highcharts.com/errors/16/
<script src="https://code.highcharts.com/highcharts.js"></script> -->
<script
src=
"https://code.highcharts.com/stock/highstock.js"
></script>
<script
src=
"https://code.highcharts.com/stock/modules/data.js"
></script>
<script
src=
"https://code.highcharts.com/stock/modules/data.js"
></script>
<script
src=
"https://code.highcharts.com/stock/modules/exporting.js"
></script>
<script
src=
"https://code.highcharts.com/stock/modules/exporting.js"
></script>
<script
src=
"https://code.highcharts.com/stock/modules/export-data.js"
></script>
<script
src=
"https://code.highcharts.com/stock/modules/export-data.js"
></script>
...
...
This diff is collapsed.
Click to expand it.
public/js/appChart.js
+
49
-
0
View file @
82d3c47d
...
@@ -139,6 +139,54 @@ const drawHeatMapHC = function (obsArray) {
...
@@ -139,6 +139,54 @@ const drawHeatMapHC = function (obsArray) {
});
});
};
};
/**
* Convert the observations' phenomenonTime from an ISO 8601 string to Unix epoch
* @param {*} obsArray - Response from SensorThings API as array
* @returns {Array}
*/
const
formatSTAResponseForLineChart
=
function
(
obsArray
)
{
const
dataSTAFormatted
=
[];
obsArray
.
forEach
((
result
)
=>
{
const
timestampObs
=
new
Date
(
result
[
0
].
slice
(
0
,
-
1
)).
getTime
();
// slice() removes trailing "Z" character in timestamp
const
valueObs
=
result
[
1
];
dataSTAFormatted
.
push
([
timestampObs
,
valueObs
]);
});
return
dataSTAFormatted
;
};
/**
* Draw a line chart using Highcharts library
* @param {*} obsArray - Response from SensorThings API
* @returns {void}
*/
const
drawLineChartHC
=
function
(
obsArray
)
{
// Create the chart
Highcharts
.
stockChart
(
"
chart-line
"
,
{
chart
:
{
zoomType
:
"
x
"
,
},
rangeSelector
:
{
selected
:
1
,
},
title
:
{
text
:
"
AAPL Stock Price
"
,
},
series
:
[
{
name
:
"
AAPL
"
,
data
:
formatSTAResponseForLineChart
(
obsArray
),
tooltip
:
{
valueDecimals
:
2
,
},
turboThreshold
:
Number
.
MAX_VALUE
,
// #3404, remove after 4.0.5 release
},
],
});
};
/**
/**
* Follows "@iot.nextLink" links in SensorThingsAPI's response
* Follows "@iot.nextLink" links in SensorThingsAPI's response
* Appends new results to existing results
* Appends new results to existing results
...
@@ -202,4 +250,5 @@ followNextLink(
...
@@ -202,4 +250,5 @@ followNextLink(
})
})
.
then
((
observationArr
)
=>
{
.
then
((
observationArr
)
=>
{
drawHeatMapHC
(
observationArr
);
drawHeatMapHC
(
observationArr
);
drawLineChartHC
(
observationArr
);
});
});
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment