4 <title>labelsKMB
</title>
6 For production (minified) code, use:
7 <script type=
"text/javascript" src=
"dygraph-combined.js"></script>
9 <script type=
"text/javascript" src=
"../dygraph-dev.js"></script>
14 <div id=
"labelsKMB" style=
"width:600px; height: 300px;"></div>
17 <div id=
"labelsKMG2" style=
"width:600px; height: 300px;"></div>
19 <p>labelsKMG2 with yValueFormatter:
</p>
20 <div id=
"labelsKMG2yValueFormatter" style=
"width:600px; height: 300px;"></div>
22 <p>labelsKMG2 with very small numbers:
</p>
23 <div id=
"labelsKMG2SmallNumbers" style=
"width:600px; height: 300px;"></div>
25 <p>The curves are exponentials. Zooming in should reveal each of the 'K',
26 'M', 'B', etc. labels.
</p>
28 <script type=
"text/javascript">
29 function round(num, places) {
30 var shift = Math.pow(
10, places);
31 return Math.round(num * shift)/shift;
34 var data = [], smalldata = [];
35 for (var i =
0, n =
1; i <
63; i++, n *=
2) {
37 smalldata.push([i, Math.pow(
10,-n)]);
40 var suffixes = ['', 'k', 'M', 'G', 'T'];
41 function formatValue(v) {
42 if (v <
1000) return v;
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)) +
51 var g = new Dygraph(document.getElementById(
"labelsKMB"), data, {
53 labels: ['Base', 'Power']
55 var g2 = new Dygraph(document.getElementById(
"labelsKMG2"), data, {
57 labels: ['Base', 'Power']
59 var g3 = new Dygraph(document.getElementById(
"labelsKMG2yValueFormatter"), data, {
61 yValueFormatter: formatValue,
62 labels: ['Base', 'Power']
65 var g4 = new Dygraph(document.getElementById(
"labelsKMG2SmallNumbers"), smalldata, {
67 labels: ['Base', 'Power']