-
Notifications
You must be signed in to change notification settings - Fork 2
/
demo2.html
executable file
·77 lines (68 loc) · 2.37 KB
/
demo2.html
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>$expand Static Chart Demonstration</title>
<style type="text/css">
body {
background-color: #C0C0C0;
font-family: sans-serif;
}
#main {
max-width: 600px;
margin: 0 auto;
}
</style>
</head>
<body>
<div id="main">
<h1>$expand Static Chart Demonstration</h1>
<noscript>JavaScript is required for this demo.</noscript>
<div id="chart"></div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.14.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highstock/4.2.6/highstock.js"></script>
<script type="text/javascript">
$(function() {
// prepare chart
var chart = new Highcharts.StockChart("chart", {
title: { text: "Loading Chart Data…" },
series: []
});
chart.showLoading();
// We start with a *link* to a datastream entity
var datastreamURI = "http://example.sensorup.com/v1.0/Datastreams(4207)";
// Retrieve the datastream
$.getJSON(datastreamURI + "?$expand=Observations", function(datastream) {
// Update some of the chart details
chart.setTitle({ text: datastream.description });
// Retrieve observations embedded in response by $expand function
var data = $.map(datastream.Observations, function(observation) {
// chart library expects an array of [timestamp, value]
var timestamp = moment(observation.phenomenonTime).valueOf();
return [[timestamp, parseFloat(observation.result)]];
});
// Observations came in reverse chronological order from the server,
// but data **must** be sorted in ascending time order for the chart
data.sort(function(a, b) {
return a[0] - b[0];
});
// Add data to chart then hide the loading indicator.
var series = chart.addSeries({
data: data,
tooltip: {
valueSuffix: " " + datastream.unitOfMeasurement.symbol
}
});
series.yAxis.update({
title: {
text: datastream.unitOfMeasurement.name + " (" + datastream.unitOfMeasurement.symbol + ")"
}
});
chart.hideLoading();
});
});
</script>
</body>
</html>