4 <title>labelsKMB
</title>
6 <script type=
"text/javascript" src=
"../excanvas.js"></script>
8 <script type=
"text/javascript" src=
"../strftime/strftime-min.js"></script>
9 <script type=
"text/javascript" src=
"../rgbcolor/rgbcolor.js"></script>
10 <script type=
"text/javascript" src=
"../dygraph-canvas.js"></script>
11 <script type=
"text/javascript" src=
"../dygraph.js"></script>
15 <div id=
"labelsKMB" style=
"width:600px; height: 300px;"></div>
18 <div id=
"labelsKMG2" style=
"width:600px; height: 300px;"></div>
20 <p>labelsKMG2 with yValueFormatter:
</p>
21 <div id=
"labelsKMG2yValueFormatter" style=
"width:600px; height: 300px;"></div>
23 <p>The curves are exponentials. Zooming in should reveal each of the 'K',
24 'M', 'B', etc. labels.
</p>
26 <script type=
"text/javascript">
27 function round(num, places) {
28 var shift = Math.pow(
10, places);
29 return Math.round(num * shift)/shift;
33 for (var i =
0, n =
1; i <
43; i++, n *=
2) {
37 var suffixes = ['', 'k', 'M', 'G', 'T'];
38 function formatValue(v) {
39 if (v <
1000) return v;
41 var magnitude = Math.floor(String(Math.floor(v)).length /
3);
42 if (magnitude
> suffixes.length -
1)
43 magnitude = suffixes.length -
1;
44 return String(round(v / Math.pow(
10, magnitude *
3),
2)) +
48 new Dygraph(document.getElementById(
"labelsKMB"), data, { labelsKMB: true });
49 new Dygraph(document.getElementById(
"labelsKMG2"), data, { labelsKMG2: true });
50 var g = new Dygraph(document.getElementById(
"labelsKMG2yValueFormatter"), data,
51 { labelsKMG2: true, yValueFormatter: formatValue });