Upendra
Upendra

Reputation: 87

Jqplot y axis value as KB/MB/TB/PB

How to get jqPlot y-axis value in KB/MB/GB/TB. I have datanode records like - no. of bytes read and write in a day, and m plotting it by JqPlot. But i wants my y-axis should contains data with notation KB/MB/TB/PB.

like instead of
1024, should be 1 KB and
4096 - 2 KB
1048576 - 1 MB
1073741824 - 1 GB

If this is possible, then please help me...

Upvotes: 2

Views: 259

Answers (1)

Ovi Faur
Ovi Faur

Reputation: 528

I believe what you are looking for is the jqplot tickOptions formatter functionality http://www.jqplot.com/docs/files/jqPlotOptions-txt.html

yaxis:{
                labelRenderer: $wnd.$.jqplot.CanvasAxisLabelRenderer,
                tickOptions: {
                    formatter: function (format, val) { 
                                if (typeof val == 'number') { 
                                    if (!format) { 
                                        format = '%.1f'; 
                                    } 
                                    if (Math.abs(val) >= 1073741824 ) {
                                        return (val / 1073741824).toFixed(1) + 'GB';
                                    }
                                    if (Math.abs(val) >= 1048576 ) {
                                        return (val / 1048576 ).toFixed(1) + 'MB';
                                    }
                                    if (Math.abs(val) >= 1024) {
                                        return (val / 1024).toFixed(1) + 'KB';
                                    }
                                    return String(val.toFixed(1));
                                } 
                                else { 
                                    return String(val); 
                                }
                    } 
                 }
            }

Upvotes: 5

Related Questions