ca21b9277a1c11142ae9ceeaab09c5895022efb2
[dygraphs.git] / tests / logscale.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <link rel="stylesheet" href="../css/dygraph.css">
5 <title>log scale</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
14 <body>
15 <center>
16 <input id='ylog' type="button" value="y log scale" onclick="setLogScale('y', true)">
17 <input id='ylinear' type="button" value="y linear scale" onclick="setLogScale('y', false)">
18 <input id='xlog' type="button" value="x log scale" onclick="setLogScale('x', true)">
19 <input id='xlinear' type="button" value="x linear scale" onclick="setLogScale('x', false)">
20 <div>Current scales: <span id="description"></span></div>
21 </center>
22
23 <h2>X axis of dates</h2>
24 <div id="div_g0" style="width:600px; height:300px;"></div>
25 <div style="font-style: italic; margin-left: 40px;">(Note: when the x-axis is dates, logscale is ignored on that axis.)</div>
26
27 <h2>X axis of numbers</h2>
28 <div id="div_g1" style="width:600px; height:300px;"></div>
29
30 <script type="text/javascript">
31 function data0() {
32 return "Date,A\n" +
33 "20101201,5\n"+
34 "20101202,10\n"+
35 "20101203,-1\n"+
36 "20101204,250\n"+
37 "20101205,1000\n"+
38 "20101206,30\n"+
39 "20101207,80\n"+
40 "20101208,100\n"+
41 "20101209,500\n"+
42 "";
43 };
44 function data1() {
45 return "X,A\n" +
46 "1,0.000001\n"+
47 "2,10\n"+
48 "3,100\n"+
49 "4,250\n"+
50 "5,1000\n"+
51 "6,30\n"+
52 "7,0\n"+
53 "8,100\n"+
54 "9,500\n"+
55 "30,500\n"+
56 "50,400\n"+
57 "100,300\n"+
58 "101,500\n"+
59 "300,200\n"+
60 "1000,100\n"+
61 "";
62 };
63
64 var g0 = new Dygraph(document.getElementById("div_g0"), data0, {});
65 var g1 = new Dygraph(document.getElementById("div_g1"), data1, {});
66 var graphs = [ g0, g1 ];
67 var scales = { x : false, y : false };
68 function setLogScale(axis, val) {
69 if (axis === 'y') {
70 for (var idx = 0; idx < graphs.length; idx++) {
71 graphs[idx].updateOptions({ logscale: val });
72 }
73 } else {
74 for (var idx = 0; idx < graphs.length; idx++) {
75 graphs[idx].updateOptions({ axes : { x : { logscale : val } } });
76 }
77 }
78 scales[axis] = val;
79 var text = "y: " + (scales.y ? "log" : "linear") + ", x: " + (scales.x ? "log" : "linear");
80 document.getElementById("description").innerText = text;
81 }
82
83 setLogScale('y', true);
84 </script>
85
86 </body>
87 </html>