如何将y轴的值转换为整数?
我目前有这个值0.0 1.0 1.5 2.0 2.5 3.0。我想将其更改为类似于0 1 2 3等的内容。
谢谢!干杯!
如何将y轴的值转换为整数?
我目前有这个值0.0 1.0 1.5 2.0 2.5 3.0。我想将其更改为类似于0 1 2 3等的内容。
谢谢!干杯!
如果我理解您的意思正确,您希望在y轴上显示整数值。
请尝试以下代码:
axesDefaults:
{
min: 0,
tickInterval: 1,
tickOptions: {
formatString: '%d'
}
}
重写createTicks函数并引入新的轴布尔属性 - integersOnly。
// jqplot adding integersOnly option for an axis
var oldCreateTicks = $.jqplot.LinearAxisRenderer.prototype.createTicks;
$.jqplot.LinearAxisRenderer.prototype.createTicks = function (plot) {
if (this.integersOnly == true) {
var db = this._dataBounds;
var min = ((this.min != null) ? this.min : db.min);
var max = ((this.max != null) ? this.max : db.max);
var range = max - min;
if (range < 3) {
if (this.min == null) {
this.min = 0;
}
this.tickInterval = 1;
}
}
return oldCreateTicks.apply(this, plot);
}
axes: {
yaxis: {
min: 0,
tickInterval: 1,
tickOptions: {
formatString: '%d'
}
}
}
只需将此应用于y轴即可。如果您有一个条形图或其他图表,并且想要隔离轴,则非常有帮助。
parseInt(y_axis)
。