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