1 <?xml version="1.0" encoding="utf-8"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4 <html xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml">
13 function drawplot(times, color) {
14 var tfact = ww / (tmax - tmin);
20 for (i = 1; i < times.length; i++) {
21 height[i] = 1 / (times[i][0] - times[i-1][0]);
22 if (hmax < height[i]) hmax = height[i];
24 height[i+1] = height[i];
27 context.moveTo(0, wh - height[1]*hfact);
28 for (i = 1; i < times.length; i++) {
29 context.lineTo((times[i][0] - tmin)*tfact,wh - height[i]*hfact);
30 context.lineTo((times[i][0] - tmin)*tfact,wh - height[i+1]*hfact);
32 context.strokeStyle = color;
35 function gotdata(data) {
36 canvas = document.getElementById("plot");
37 context = canvas.getContext("2d");
38 ww = canvas.offsetWidth;
39 wh = canvas.offsetHeight;
42 document.getElementById("cold").innerHTML = data.current.cold;
43 document.getElementById("hot").innerHTML = data.current.hot;
44 drawplot(data.cold, "blue");
45 drawplot(data.hot, "red");
65 border: solid 1px black;
70 background-color: #d0e0ff;
74 background-color: #ffd0e0;
79 border: solid 1px black;
82 <title>Water Meters</title>
85 <div id="currentvals">
87 <div class="current" id="cold">cold</div>
88 <div class="current" id="hot">hot</div>
91 <canvas id="plot" width="640" height = "480"></canvas>
96 var xmlhttp = new XMLHttpRequest();
97 var url = "query.cgi";
99 xmlhttp.onreadystatechange = function() {
100 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
101 document.getElementById("debug").innerHTML = xmlhttp.responseText;
102 var myData = JSON.parse(xmlhttp.responseText);
106 xmlhttp.open("GET", url, true);