Fix errors/warnings in tests/*.html
[dygraphs.git] / tests / x-axis-formatter.html
CommitLineData
54425b14 1<!DOCTYPE html>
bf640e56
AV
2<html>
3 <head>
31eddad3 4 <title>X Axis Label Formatting</title>
7e5ddc94
DV
5 <!--
6 For production (minified) code, use:
7 <script type="text/javascript" src="dygraph-combined.js"></script>
8 -->
fbd6834a 9 <script type="text/javascript" src="../dist/dygraph.js"></script>
7e5ddc94 10
bf640e56
AV
11 </head>
12 <body>
13 <p>Original data:</p>
14 <div id="normal" style="width:600px; height:300px;"></div>
15
16 <p>Same data, but offset by 2 hours with the date formatter:</p>
17 <div id="offby2" style="width:600px; height:300px;"></div>
18
19 <p>Same data, but always displaying HH:MM:SS:</p>
20 <div id="seconds" style="width:600px; height:300px;"></div>
21
22 <script type="text/javascript">
23 function HourlyData() {
24 return "" +
25 "Date,A,B\n" +
26 "2009/07/12 00:00:00,3,4\n" +
27 "2009/07/12 01:00:00,5,6\n" +
28 "2009/07/12 02:00:00,7,6\n" +
29 "2009/07/12 03:00:00,6,5\n" +
30 "2009/07/12 04:00:00,4,7\n" +
31 "2009/07/12 05:00:00,3,6\n" +
32 "2009/07/12 06:00:00,4,6"
33 }
2b66af4f
DV
34 function zeropad(x) {
35 return (x < 10) ? '0' + x : x;
36 }
bf640e56 37
f6fbf9e0 38 var g1 = new Dygraph(
bf640e56
AV
39 document.getElementById("normal"),
40 HourlyData()
41 );
42
f6fbf9e0 43 var g2 = new Dygraph(
bf640e56
AV
44 document.getElementById("offby2"),
45 HourlyData(),
46 {
48e614ac
DV
47 axes: {
48 x: {
4c765ad9
JPB
49 axisLabelFormatter: function(d, gran, opts) {
50 return Dygraph.dateAxisLabelFormatter(new Date(d.getTime() + 7200*1000), gran, opts);
48e614ac 51 }
bf640e56 52 }
48e614ac 53 }
bf640e56
AV
54 });
55
f6fbf9e0 56 var g3 = new Dygraph(
bf640e56
AV
57 document.getElementById("seconds"),
58 HourlyData(),
59 {
48e614ac
DV
60 axes: {
61 x: {
2b66af4f 62 axisLabelWidth: 70,
48e614ac 63 axisLabelFormatter: function(d, gran) {
2b66af4f
DV
64 return zeropad(d.getHours()) + ":"
65 + zeropad(d.getMinutes()) + ":"
66 + zeropad(d.getSeconds());
48e614ac 67 }
bf640e56 68 }
48e614ac 69 }
bf640e56
AV
70 });
71 </script>
72 </body>
73</html>