File: logscale.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 (85 lines) | stat: -rw-r--r-- 2,805 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
75
76
77
78
79
80
81
82
83
84
85
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>log scale</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>
    <center>
      <input id='ylog' type="button" value="y log scale" onclick="setLogScale('y', true)">
      <input id='ylinear' type="button" value="y linear scale" onclick="setLogScale('y', false)">
      <input id='xlog' type="button" value="x log scale" onclick="setLogScale('x', true)">
      <input id='xlinear' type="button" value="x linear scale" onclick="setLogScale('x', false)">
      <div>Current scales: <span id="description"></span></div>
    </center>

    <h2>X axis of dates</h2>
    <div id="div_g0" style="width:600px; height:300px;"></div>
    <div style="font-style: italic; margin-left: 40px;">(Note: when the x-axis is dates, logscale is ignored on that axis.)</div>

    <h2>X axis of numbers</h2>
    <div id="div_g1" style="width:600px; height:300px;"></div>

    <script type="text/javascript"><!--//--><![CDATA[//><!--
    Dygraph.onDOMready(function onDOMready() {
      function data0() {
        return "Date,A\n" +
        "2010-12-01,5\n"+
        "2010-12-02,10\n"+
        "2010-12-03,-1\n"+
        "2010-12-04,250\n"+
        "2010-12-05,1000\n"+
        "2010-12-06,30\n"+
        "2010-12-07,80\n"+
        "2010-12-08,100\n"+
        "2010-12-09,500\n"+
        "";
      };
      function data1() {
        return "X,A\n" +
        "1,0.000001\n"+
        "2,10\n"+
        "3,100\n"+
        "4,250\n"+
        "5,1000\n"+
        "6,30\n"+
        "7,0\n"+
        "8,100\n"+
        "9,500\n"+
        "30,500\n"+
        "50,400\n"+
        "100,300\n"+
        "101,500\n"+
        "300,200\n"+
        "1000,100\n"+
        "";
      };

      var g0 = new Dygraph(document.getElementById("div_g0"), data0, {});
      var g1 = new Dygraph(document.getElementById("div_g1"), data1, {});
      var graphs = [ g0, g1 ];
      var scales = { x : false, y : false };
      setLogScale = function setLogScale(axis, val) {
        if (axis === 'y') {
          for (var idx = 0; idx < graphs.length; idx++) {
            graphs[idx].updateOptions({ logscale: val });
          }
        } else {
          for (var idx = 0; idx < graphs.length; idx++) {
            graphs[idx].updateOptions({ axes : { x : {  logscale : val } } });
          }
        }
        scales[axis] = val;
        var text = "y: " + (scales.y ? "log" : "linear") + ", x: " + (scales.x ? "log" : "linear");
        document.getElementById("description").innerText = text;
      }

      setLogScale('y', true);
    });
    //--><!]]></script>
  </body>
</html>