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

标签 jqplot

如何获取 jqPlot y 轴值(以 KB/MB/GB/TB 为单位)。我有数据节点记录,例如 - 不。一天中读取和写入的字节数,并通过 JqPlot 绘制它。但我希望我的 y 轴应包含带有 KB/MB/TB/PB 表示法的数据。

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

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

最佳答案

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

关于Jqplot y轴值为KB/MB/TB/PB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19088326/

相关文章:

jquery - 如何在jqplot中渲染json数据

javascript - 如何在此 jqplot 脚本中旋转 x 轴标签

javascript - 使用 jqPlot 在 Android WebView 中制作图表

javascript - 使用 javascript 在浏览器中使用折线图可视化日期特定数据

javascript - 如何设置图例(jqplot)中各个标签的颜色?

jquery - Jqplot 多行刻度/标签

jquery - jqplot 饼图无法正确呈现。

jquery - jqPlot 饼图 - 如何捕获对图例项的点击?

javascript - jqPlot 系列上的 jqplotClick 事件(iOS 设备 Safari 浏览器)

javascript - JQPlot打印