Commit | Line | Data |
---|---|---|
02ecfa7a DV |
1 | <html> |
2 | <head> | |
3 | <title>labelsKMB</title> | |
4 | <!--[if IE]> | |
a2b2c3a1 | 5 | <script type="text/javascript" src="../excanvas.js"></script> |
02ecfa7a | 6 | <![endif]--> |
d37dca40 DV |
7 | <script type="text/javascript" src="../strftime/strftime-min.js"></script> |
8 | <script type="text/javascript" src="../rgbcolor/rgbcolor.js"></script> | |
02ecfa7a DV |
9 | <script type="text/javascript" src="../dygraph-canvas.js"></script> |
10 | <script type="text/javascript" src="../dygraph.js"></script> | |
11 | </head> | |
12 | <body> | |
13 | <p>labelsKMB:</p> | |
14 | <div id="labelsKMB" style="width:600px; height: 300px;"></div> | |
15 | ||
d160cc3b | 16 | <p>labelsKMG2:</p> |
02ecfa7a DV |
17 | <div id="labelsKMG2" style="width:600px; height: 300px;"></div> |
18 | ||
d160cc3b NK |
19 | <p>labelsKMG2 with yValueFormatter:</p> |
20 | <div id="labelsKMG2yValueFormatter" style="width:600px; height: 300px;"></div> | |
21 | ||
02ecfa7a DV |
22 | <p>The curves are exponentials. Zooming in should reveal each of the 'K', |
23 | 'M', 'B', etc. labels.</p> | |
24 | ||
25 | <script type="text/javascript"> | |
029da4b6 DV |
26 | function round(num, places) { |
27 | var shift = Math.pow(10, places); | |
28 | return Math.round(num * shift)/shift; | |
29 | }; | |
30 | ||
02ecfa7a DV |
31 | var data = []; |
32 | for (var i = 0, n = 1; i < 43; i++, n *= 2) { | |
33 | data.push([i, n]); | |
34 | } | |
35 | ||
d160cc3b NK |
36 | var suffixes = ['', 'k', 'M', 'G', 'T']; |
37 | function formatValue(v) { | |
38 | if (v < 1000) return v; | |
39 | ||
40 | var magnitude = Math.floor(String(Math.floor(v)).length / 3); | |
41 | if (magnitude > suffixes.length - 1) | |
42 | magnitude = suffixes.length - 1; | |
029da4b6 | 43 | return String(round(v / Math.pow(10, magnitude * 3), 2)) + |
d160cc3b NK |
44 | suffixes[magnitude]; |
45 | } | |
46 | ||
02ecfa7a DV |
47 | new Dygraph(document.getElementById("labelsKMB"), data, { labelsKMB: true }); |
48 | new Dygraph(document.getElementById("labelsKMG2"), data, { labelsKMG2: true }); | |
d160cc3b NK |
49 | var g = new Dygraph(document.getElementById("labelsKMG2yValueFormatter"), data, |
50 | { labelsKMG2: true, yValueFormatter: formatValue }); | |
02ecfa7a DV |
51 | </script> |
52 | </body> | |
53 | </html> |