Merge pull request #139 from klausw-g/stacked-NaN
[dygraphs.git] / tests / labelsKMB.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7; IE=EmulateIE9">
5 <title>labelsKMB</title>
6 <!--[if IE]>
7 <script type="text/javascript" src="../excanvas.js"></script>
8 <![endif]-->
9 <!--
10 For production (minified) code, use:
11 <script type="text/javascript" src="dygraph-combined.js"></script>
12 -->
13 <script type="text/javascript" src="../dygraph-dev.js"></script>
14
15 </head>
16 <body>
17 <p>labelsKMB:</p>
18 <div id="labelsKMB" style="width:600px; height: 300px;"></div>
19
20 <p>labelsKMG2:</p>
21 <div id="labelsKMG2" style="width:600px; height: 300px;"></div>
22
23 <p>labelsKMG2 with yValueFormatter:</p>
24 <div id="labelsKMG2yValueFormatter" style="width:600px; height: 300px;"></div>
25
26 <p>The curves are exponentials. Zooming in should reveal each of the 'K',
27 'M', 'B', etc. labels.</p>
28
29 <script type="text/javascript">
30 function round(num, places) {
31 var shift = Math.pow(10, places);
32 return Math.round(num * shift)/shift;
33 };
34
35 var data = [];
36 for (var i = 0, n = 1; i < 43; i++, n *= 2) {
37 data.push([i, n]);
38 }
39
40 var suffixes = ['', 'k', 'M', 'G', 'T'];
41 function formatValue(v) {
42 if (v < 1000) return v;
43
44 var magnitude = Math.floor(String(Math.floor(v)).length / 3);
45 if (magnitude > suffixes.length - 1)
46 magnitude = suffixes.length - 1;
47 return String(round(v / Math.pow(10, magnitude * 3), 2)) +
48 suffixes[magnitude];
49 }
50
51 var g = new Dygraph(document.getElementById("labelsKMB"), data, { labelsKMB: true });
52 var g2 = new Dygraph(document.getElementById("labelsKMG2"), data, { labelsKMG2: true });
53 var g3 = new Dygraph(document.getElementById("labelsKMG2yValueFormatter"), data,
54 { labelsKMG2: true, yValueFormatter: formatValue });
55 </script>
56 </body>
57 </html>