2013-09-30 62 views
1

如何获取jqPlot y轴值(KB/MB/GB/TB)。我有datanode记录像 - 没有。的字节在一天内读写,并且通过JqPlot绘制它。但我希望我的Y轴应该包含符号KB/MB/TB/PB的数据。Jqplot y轴值为KB/MB/TB/PB

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

如果这是可能的,那么请帮我...

回答

4

我相信你正在寻找的是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); 
           } 
        } 
       } 
      } 
+0

太感谢你了.. 。没错,那......我想要的...... 超级... – Upendra