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