2013-09-30 139 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