Add ability to specify the formatter used for the x axis.
[dygraphs.git] / tests / x-axis-formatter.html
diff --git a/tests/x-axis-formatter.html b/tests/x-axis-formatter.html
new file mode 100644 (file)
index 0000000..96b3e06
--- /dev/null
@@ -0,0 +1,64 @@
+<html>
+  <head>
+    <title>hourly</title>
+    <!--[if IE]>
+    <script type="text/javascript" src="excanvas.js"></script>
+    <![endif]-->
+    <script type="text/javascript" src="../strftime/strftime-min.js"></script>
+    <script type="text/javascript" src="../rgbcolor/rgbcolor.js"></script>
+    <script type="text/javascript" src="../dygraph-canvas.js"></script>
+    <script type="text/javascript" src="../dygraph.js"></script>
+  </head>
+  <body>
+    <p>Original data:</p>
+    <div id="normal" style="width:600px; height:300px;"></div>
+
+    <p>Same data, but offset by 2 hours with the date formatter:</p>
+    <div id="offby2" style="width:600px; height:300px;"></div>
+
+    <p>Same data, but always displaying HH:MM:SS:</p>
+    <div id="seconds" style="width:600px; height:300px;"></div>
+
+    <script type="text/javascript">
+      function HourlyData() {
+        return "" +
+          "Date,A,B\n" +
+          "2009/07/12 00:00:00,3,4\n" +
+          "2009/07/12 01:00:00,5,6\n" +
+          "2009/07/12 02:00:00,7,6\n" +
+          "2009/07/12 03:00:00,6,5\n" +
+          "2009/07/12 04:00:00,4,7\n" +
+          "2009/07/12 05:00:00,3,6\n" +
+          "2009/07/12 06:00:00,4,6"
+      }
+
+      new Dygraph(
+            document.getElementById("normal"),
+            HourlyData()
+          );
+
+      new Dygraph(
+            document.getElementById("offby2"),
+            HourlyData(),
+            { 
+              xAxisLabelFormatter:
+                function(d, gran) {
+                  return Dygraph.dateAxisFormatter(new Date(d.getTime() + 7200*1000), gran);
+                }
+            });
+
+      new Dygraph(
+            document.getElementById("seconds"),
+            HourlyData(),
+            { 
+              xAxisLabelWidth: 70,
+              xAxisLabelFormatter:
+                function(d, gran) {
+                  return Dygraph.zeropad(d.getHours()) + ":"
+                      + Dygraph.zeropad(d.getMinutes()) + ":"
+                      + Dygraph.zeropad(d.getSeconds());
+                }
+            });
+    </script>
+  </body>
+</html>