// Add formatted labels to the ticks.
var k;
var k_labels = [];
+ var m_labels = [];
if (opts("labelsKMB")) {
k = 1000;
k_labels = [ "K", "M", "B", "T", "Q" ];
if (k) Dygraph.warn("Setting both labelsKMB and labelsKMG2. Pick one!");
k = 1024;
k_labels = [ "k", "M", "G", "T", "P", "E" ];
+ m_labels = [ "m", "u", "n", "p", "f", "a", "z", "y" ];
}
var formatter = opts('axisLabelFormatter');
}
}
}
+ if(opts("labelsKMG2")){
+ tickV = String(tickV.toExponential());
+ if(tickV.split('e-').length === 2 && tickV.split('e-')[1] >= 3){
+ if(tickV.split('e-')[1] % 3 > 0) {
+ label = Dygraph.round_(tickV.split('e-')[0] /
+ Math.pow(10,(tickV.split('e-')[1] % 3)),
+ opts('digitsAfterDecimal'));
+ } else {
+ label = Number(tickV.split('e-')[0]).toFixed(2);
+ }
+ label += m_labels[Math.floor(tickV.split('e-')[1] / 3) - 1];
+ }
+ }
ticks[i].label = label;
}
<p>labelsKMG2 with yValueFormatter:</p>
<div id="labelsKMG2yValueFormatter" style="width:600px; height: 300px;"></div>
+ <p>labelsKMG2 with very small numbers:</p>
+ <div id="labelsKMG2SmallNumbers" style="width:600px; height: 300px;"></div>
+
<p>The curves are exponentials. Zooming in should reveal each of the 'K',
'M', 'B', etc. labels.</p>
return Math.round(num * shift)/shift;
};
- var data = [];
+ var data = [], smalldata = [];
for (var i = 0, n = 1; i < 63; i++, n *= 2) {
data.push([i, n]);
+ smalldata.push([i, Math.pow(10,-n)]);
}
var suffixes = ['', 'k', 'M', 'G', 'T'];
yValueFormatter: formatValue,
labels: ['Base', 'Power']
});
+
+ var g4 = new Dygraph(document.getElementById("labelsKMG2SmallNumbers"), smalldata, {
+ labelsKMG2: true,
+ labels: ['Base', 'Power']
+ });
</script>
</body>
</html>