Dygraph.dateString_: shows milliseconds if any. (#774)
[dygraphs.git] / tests / x-axis-formatter.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>X Axis Label Formatting</title>
5 <!--
6 For production (minified) code, use:
7 <script type="text/javascript" src="dygraph-combined.js"></script>
8 -->
9 <script type="text/javascript" src="../dist/dygraph.js"></script>
10
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 }
34 function zeropad(x) {
35 return (x < 10) ? '0' + x : x;
36 }
37
38 var g1 = new Dygraph(
39 document.getElementById("normal"),
40 HourlyData()
41 );
42
43 var g2 = new Dygraph(
44 document.getElementById("offby2"),
45 HourlyData(),
46 {
47 axes: {
48 x: {
49 axisLabelFormatter: function(d, gran, opts) {
50 return Dygraph.dateAxisLabelFormatter(new Date(d.getTime() + 7200*1000), gran, opts);
51 }
52 }
53 }
54 });
55
56 var g3 = new Dygraph(
57 document.getElementById("seconds"),
58 HourlyData(),
59 {
60 axes: {
61 x: {
62 axisLabelWidth: 70,
63 axisLabelFormatter: function(d, gran) {
64 return zeropad(d.getHours()) + ":"
65 + zeropad(d.getMinutes()) + ":"
66 + zeropad(d.getSeconds());
67 }
68 }
69 }
70 });
71 </script>
72 </body>
73 </html>