Debian Codegraph @

examples/realtime/index.html

raw ◀ ▶
1 Debian patch touch this file
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5 <title>Flot Examples: Real-time updates</title>
6 <link href="../examples.css" rel="stylesheet" type="text/css">
•7 <script language="javascript" type="text/javascript" src="/usr/share/javascript/jquery/jquery.js"></script>
8 <script language="javascript" type="text/javascript" src="/usr/share/javascript/jquery-flot/jquery.canvaswrapper.js"></script>
9 <script language="javascript" type="text/javascript" src="/usr/share/javascript/jquery-flot/jquery.colorhelpers.js"></script>
10 <script language="javascript" type="text/javascript" src="/usr/share/javascript/jquery-flot/jquery.flot.js"></script>
11 <script language="javascript" type="text/javascript" src="/usr/share/javascript/jquery-flot/jquery.flot.saturated.js"></script>
12 <script language="javascript" type="text/javascript" src="/usr/share/javascript/jquery-flot/jquery.flot.browser.js"></script>
13 <script language="javascript" type="text/javascript" src="/usr/share/javascript/jquery-flot/jquery.flot.drawSeries.js"></script>
14 <script language="javascript" type="text/javascript" src="/usr/share/javascript/jquery-flot/jquery.flot.uiConstants.js"></script>
15 <script type="text/javascript">
16
17 $(function() {
18
19 // We use an inline data source in the example, usually data would
20 // be fetched from a server
21
22 var data = [],
23 totalPoints = 300;
24
25 function getRandomData() {
26
27 if (data.length > 0)
28 data = data.slice(1);
29
30 // Do a random walk
31
32 while (data.length < totalPoints) {
33
34 var prev = data.length > 0 ? data[data.length - 1] : 50,
35 y = prev + Math.random() * 10 - 5;
36
37 if (y < 0) {
38 y = 0;
39 } else if (y > 100) {
40 y = 100;
41 }
42
43 data.push(y);
44 }
45
46 // Zip the generated y values with the x values
47
48 var res = [];
49 for (var i = 0; i < data.length; ++i) {
50 res.push([i, data[i]])
51 }
52
53 return res;
54 }
55
56 // Set up the control widget
57
58 var updateInterval = 30;
59 $("#updateInterval").val(updateInterval).change(function () {
60 var v = $(this).val();
61 if (v && !isNaN(+v)) {
62 updateInterval = +v;
63 if (updateInterval < 1) {
64 updateInterval = 1;
65 } else if (updateInterval > 2000) {
66 updateInterval = 2000;
67 }
68 $(this).val("" + updateInterval);
69 }
70 });
71
72 var plot = $.plot("#placeholder", [ getRandomData() ], {
73 series: {
74 shadowSize: 0 // Drawing is faster without shadows
75 },
76 yaxis: {
77 min: 0,
78 max: 100
79 },
80 xaxis: {
81 show: false
82 }
83 });
84
85 function update() {
86
87 plot.setData([getRandomData()]);
88
89 // Since the axes don't change, we don't need to call plot.setupGrid()
90
91 plot.draw();
92 setTimeout(update, updateInterval);
93 }
94
95 update();
96
97 // Add the Flot version string to the footer
98
99 $("#footer").prepend("Flot " + $.plot.version + " &ndash; ");
100 });
101
102 </script>
103 </head>
104 <body>
105
106 <div id="header">
107 <h2>Real-time updates</h2>
108 </div>
109
110 <div id="content">
111
112 <div class="demo-container">
113 <div id="placeholder" class="demo-placeholder"></div>
114 </div>
115
116 <p>You can update a chart periodically to get a real-time effect by using a timer to insert the new data in the plot and redraw it.</p>
117
118 <p>Time between updates: <input id="updateInterval" type="text" value="" style="text-align: right; width:5em"> milliseconds</p>
119
120 </div>
121
122 <div id="footer">
123 Copyright &copy; 2007 - 2014 IOLA and Ole Laursen
124 </div>
125
126 </body>
127 </html>