File: x-axis-formatter.html

package info (click to toggle)
dygraphs 2.2.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,340 kB
  • sloc: javascript: 24,842; sh: 800; python: 581; makefile: 45
file content (74 lines) | stat: -rw-r--r-- 2,277 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>X Axis Label Formatting</title>

    <link rel="stylesheet" type="text/css" href="../dist/dygraph.css" />
    <link rel="stylesheet" type="text/css" href="../common/vextlnk.css" />
    <script type="text/javascript" src="../dist/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"><!--//--><![CDATA[//><!--
    Dygraph.onDOMready(function onDOMready() {
      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"
      }
      function zeropad(x) {
        return (x < 10) ? '0' + x : x;
      }

      var g1 = new Dygraph(
            document.getElementById("normal"),
            HourlyData()
          );

      var g2 = new Dygraph(
            document.getElementById("offby2"),
            HourlyData(),
            {
              axes: {
                x: {
                  axisLabelFormatter: function(d, gran, opts) {
                      return Dygraph.dateAxisLabelFormatter(new Date(d.getTime() + 7200*1000), gran, opts);
                  }
                }
              }
            });

      var g3 = new Dygraph(
            document.getElementById("seconds"),
            HourlyData(),
            {
              axes: {
                x: {
                  axisLabelWidth: 70,
                  axisLabelFormatter: function(d, gran) {
                    return zeropad(d.getHours()) + ":"
                        + zeropad(d.getMinutes()) + ":"
                        + zeropad(d.getSeconds());
                  }
                }
              }
            });
    });
    //--><!]]></script>
  </body>
</html>