-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharcade-popup-line-chart-related-table
45 lines (42 loc) · 1.42 KB
/
arcade-popup-line-chart-related-table
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Order the data by their measure date to get the first and last measurement
var relatedMeasures = OrderBy(FeatureSetByRelationshipName($feature, "gauge_measure_data"), "datetime asc")
var relatedMeasures_reverse = OrderBy(FeatureSetByRelationshipName($feature, "gauge_measure_data"), "datetime desc")
var firstDate = Text(First(relatedMeasures).datetime, "DD.MM.YYYY")
var lastDate = Text(First(relatedMeasures_reverse).datetime, "DD.MM.YYYY")
// Prepare the properties for the line chart
var chartValues = {}
var chartNames = []
var title = 'Waterlevel measurement from ' + firstDate + ' to ' + lastDate
var caption = 'Chart shows the waterlevel measurement during a day (measured every 15 minutes). All values are in cm.'
// at the date and the corresponding measurement value for the chart
for (var f in relatedMeasures) {
var shortDate = Text(f.datetime, "DD.MM.YY h:mm A")
var Value = 0
if(!IsEmpty(f.value)) {
Value = f.value*100
chartValues[shortDate] = Value
Push(chartNames, shortDate)
}
}
// if there is data, then return a line chart
if(count(chartNames) >= 1) {
return {
type: 'media',
attributes: chartValues,
mediaInfos: [{
type: 'linechart',
title: title,
caption: caption,
value : {
fields: chartNames
}
}]
}
}
// if no data is given, than do not return a chart
else {
return {
type: 'text',
text: 'Ups, we do not have any data here!'
}
}