如何获取 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/