Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

Consider formatting Y-Axis values

Open nakkeeran opened this issue 10 years ago • 2 comments

Code from Rickshaw,

Rickshaw.namespace('Rickshaw.Fixtures.Number');

Rickshaw.Fixtures.Number.formatKMBT = function(y) {
    var abs_y = Math.abs(y);
    if (abs_y >= 1000000000000)   { return y / 1000000000000 + "T" }
    else if (abs_y >= 1000000000) { return y / 1000000000 + "B" }
    else if (abs_y >= 1000000)    { return y / 1000000 + "M" }
    else if (abs_y >= 1000)       { return y / 1000 + "K" }
    else if (abs_y < 1 && y > 0)  { return y.toFixed(2) }
    else if (abs_y === 0)         { return '' }
    else                      { return y }
};

Rickshaw.Fixtures.Number.formatBase1024KMGTP = function(y) {
    var abs_y = Math.abs(y);
    if (abs_y >= 1125899906842624)  { return y / 1125899906842624 + "P" }
    else if (abs_y >= 1099511627776){ return y / 1099511627776 + "T" }
    else if (abs_y >= 1073741824)   { return y / 1073741824 + "G" }
    else if (abs_y >= 1048576)      { return y / 1048576 + "M" }
    else if (abs_y >= 1024)         { return y / 1024 + "K" }
    else if (abs_y < 1 && y > 0)    { return y.toFixed(2) }
    else if (abs_y === 0)           { return '' }
    else                        { return y }
};

https://github.com/shutterstock/rickshaw/blob/master/src/js/Rickshaw.Fixtures.Number.js

nakkeeran avatar Oct 05 '16 20:10 nakkeeran

I agree that this is probably useful for some charts, but I don't think we should have it by default in the core. There are too many specific cases that we cannot account for and that would increase the size of the library.

etimberg avatar Oct 05 '16 22:10 etimberg

👍

nakkeeran avatar Oct 05 '16 22:10 nakkeeran