I have a chart that is tracking file size. I want to set up an axis (Y) that displays file size with a proper Mebibyte suffix ex: KiB, MiB, GiB etc.
Now, I am feeding in data in bytes so theoretically a simple .tickFormat()
method followed by a d3.format()
should do the trick. Unfortunately that's not the case, since file size is actually multiples of 1024 (or 2^20) and not typical SI 10^6. What that means is that my line starts to plot but the axis is all weird.
Take for example a file size of 587108352 and if round that up to nearest MB i get 560MiB (using the 1024 (2^20) multiplier).
How can I setup my axis to work with that?
I tried this:
yAxis = d3.axisLeft(y)
.tickFormat(function (d) {
return d3.format(scope.formatOptions.specifier)(d * scope.formatOptions.multiplier) + scope.formatOptions.suffix;
});
Where format options object is:
vm.FormatObjectSize = {
specifier: ".0s", // decimal notation with an SI prefix, rounded to significant digits.
multiplier: 1, // none
suffix: "b" // bytes
};
That doesn't exactly work too well: