-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrealtime-charts.html
140 lines (121 loc) · 3.96 KB
/
realtime-charts.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!DOCTYPE HTML>
<html>
<head>
<title>Pramodh - realtime charts</title>
<script src="//code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/canvasjs/1.7.0/canvasjs.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-slider/9.9.0/bootstrap-slider.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-slider/9.9.0/css/bootstrap-slider.min.css">
<style>
.tooltip{
display: none;
}
.heading{
font-size: 22px;
height: 100px;
text-align: center;
}
.block{
width: 100%; display: block; clear:both; width: 100%; display: block; clear:both;
}
.slider-content{
width: 45%; margin: 15px; float: left;
}
.chart-canvas{
height: 250px; width: 30%; float: left; padding: 15px;
}
</style>
<script type="text/javascript">
// init values
var aData = [{x: 1, y: 500}];
var bData = [{x: 1, y: 300}];
var cData = [{x: 1, y: 400}];
var updateInterval = 100; // 100ms
var xVal = 0;
var colors = {
plotAContainer: "#4661EE",
plotBContainer: "#1BCDD1",
plotCContainer: "#23BFAA"
}
// init charts
function initChart(id, title, dataPoints){
var chart = new CanvasJS.Chart(id,
{
title:{
text: title
},
animationEnabled: true,
data: [
{
type: "splineArea",
color: colors[id],
dataPoints: dataPoints
}
]
});
chart.render();
return chart;
}
// update charts with form data
var updatePointsFromForm = function (id, dataPoints) {
yVal = parseInt($(id).val());
dataPoints.push({x: xVal,y: yVal,});
if (dataPoints.length > 10 ) { dataPoints.shift(); }
};
// update chart with form computation
function updatePlotC(inputA, inputB, dataPoints){
a = parseInt($(inputA).val());
b = parseInt($(inputB).val());
yVal = (a+b)/2;
dataPoints.push({x: xVal,y: yVal,});
if (dataPoints.length > 10 ) { dataPoints.shift(); }
}
window.onload = function () {
// load charts
var chartA = initChart("plotAContainer", "Plot A", aData);
var chartB = initChart("plotBContainer", "Plot B", bData);
var chartC = initChart("plotCContainer", "Plot C", cData);
// load sliders
$("#inputA").slider();
$("#inputA").on("slide", function(slideEvt) {
$("#inputASliderVal").text(slideEvt.value);
});
$("#inputB").slider();
$("#inputB").on("slide", function(slideEvt) {
$("#inputBSliderVal").text(slideEvt.value);
});
// load interval data
setInterval(function(){
xVal++;
updatePointsFromForm("#inputA", aData);
updatePointsFromForm("#inputB", bData);
updatePlotC("#inputA", "#inputB", cData);
chartA.render();
chartB.render();
chartC.render();
}, updateInterval);
}
</script>
</head>
<body>
<div class="heading">
Realtime charts by Pramodh
</div>
<div class="block">
<div class="slider-content">
<input id="inputA" type="text" data-slider-min="0" data-slider-max="1000" data-slider-step="1" data-slider-value="500" />
<span id="inputACurrentSliderValLabel">A is <span id="inputASliderVal">500</span></span>
</div>
<div class="slider-content">
<input id="inputB" type="text" data-slider-min="0" data-slider-max="1000" data-slider-step="1" data-slider-value="300" />
<span id="inputBCurrentSliderValLabel">B is <span id="inputBSliderVal">300</span></span>
</div>
</div>
<div class="block">
<div id="plotAContainer" class="chart-canvas"></div>
<div id="plotBContainer" class="chart-canvas"></div>
<div id="plotCContainer" class="chart-canvas"></div>
</div>
</body>
</html>