kalombo
kalombo

Reputation: 869

How can i trim axis numbers in jquery flot?

I am drawing graph real-time and i have big numbers on axis like "200000000". It is hard to read it. I need it to be like "200kk" or anything else. Help?

Upvotes: 0

Views: 102

Answers (1)

Rituraj ratan
Rituraj ratan

Reputation: 10388

 function FormatterNum(num) {
    if (num >= 1000000000) {
        return (num / 1000000000).toFixed(1) + 'G';
    }
    if (num >= 1000000) {
        return (num / 1000000).toFixed(1) + 'M';
    }
    if (num >= 1000) {
        return (num / 1000).toFixed(1) + 'K';
    }
    return num;
}
console.log(FormatterNum(6000));

reference How to format a number as 2.5K if a thousand or more, otherwise 900 in javascript?

Upvotes: 2

Related Questions