Jqplot y轴值为KB/MB/TB/PB

Upe*_*dra 2 jqplot

如何以KB/MB/GB/TB为单位获取jqPlot y轴值.我有datanode记录,如 - 没有.一天中读取和写入的字节数,并通过JqPlot绘制它.但我希望我的y轴应包含带有KB/MB/TB/PB符号的数据.

like instead of
1024, should be 1 KB and
4096 - 2 KB
1048576 - 1 MB
1073741824 - 1 GB
Run Code Online (Sandbox Code Playgroud)

如果可以的话,请帮帮我...

Ovi*_*aur 5

我相信你要找的是jqplot tickOptions格式化程序功能 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); 
                                }
                    } 
                 }
            }
Run Code Online (Sandbox Code Playgroud)