Flot中轴的逗号分隔数字 [英] Comma Separated Numbers For an Axis in Flot
本文介绍了Flot中轴的逗号分隔数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法让Flot使轴编号以逗号分隔?
Is there a way to have Flot make axis numbers be comma-separated?
例如,代替1000000而不是1,000,000
So for example, instead of 1000000 have 1,000,000
推荐答案
您可以使用轴的tickFormatter属性来实现。
You can do that by using the tickFormatter property of the axis.
xaxis: {
tickFormatter: function(val, axis) {
// insert comma logic here and return the string
}
}
资料来源: http://people.iola.dk/olau/flot/API.txt (在自定义轴下)
Source: http://people.iola.dk/olau/flot/API.txt (under "Customizing the axes")
此页面具有使用逗号格式化数字的功能: http://www.mredkj.com/javascript/nfbasic。 html
This page has a function to format numbers with commas: http://www.mredkj.com/javascript/nfbasic.html
例如yaxis:
$(function () {
var plotarea = $("#plotarea");
$.plot( plotarea , [data], {
xaxis: {mode: "time", timeformat: "%m/%d %H:%M:%S"},
yaxis: {tickFormatter: function numberWithCommas(x) {
return x.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ",");
}
},
points: { show: true },
lines: { show: true, fill: true }
} );
});
这篇关于Flot中轴的逗号分隔数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文