gpt4 book ai didi

javascript - float 标记函数,轴未定义?

转载 作者:行者123 更新时间:2023-12-03 11:54:53 25 4
gpt4 key购买 nike

当我使用以下选项创建图表时,flot 会正确绘制图表:

var options = {
colors: trendcolors,
series: {
points: {
show: true
},
lines: {
show: true
}
},
xaxis: {
mode: "time",
axisLabel: "Date/Time",
tickLength: 0
},
yaxis: {
axisLabel: "Duration (Sec)"
},
selection: {
mode: "x"
},
grid: {
hoverable: true,
clickable: true,
markings: function (axes) {
var markings = [];
var date = new Date(axes.xaxis.min);
date.setUTCSeconds(0);
date.setUTCMinutes(0);
date.setUTCHours(0);
var i = date.getTime();
do {
markings.push({xaxis:{from: i, to: i + (24 * 60 * 60 * 1000) }, color: colormarking } );
i += ((24 * 60 * 60 * 1000) * 2);
} while (i < axes.xaxis.max);
return markings;
}
},
legend: {
labelFormatter: function(label, series) {
return label + " (" + series.data.length + ")";
}
}
};

但是,当我将标记匿名函数更改为标准函数时,会发生错误,并且 flot 无法绘制图形,因为 fMarkings 行上未定义“轴”。为什么是这样?有什么不同?

    var options = {
colors: trendcolors,
series: {
points: {
show: true
},
lines: {
show: true
}
},
xaxis: {
mode: "time",
axisLabel: "Date/Time",
tickLength: 0
},
yaxis: {
axisLabel: "Duration (Sec)"
},
selection: {
mode: "x"
},
grid: {
hoverable: true,
clickable: true,
markings: fMarkings(axes)
},
legend: {
labelFormatter: function(label, series) {
return label + " (" + series.data.length + ")";
}
}
};

顺便说一下,fMarkings 是在另一个 js block 中全局定义的。

最佳答案

markings 参数需要一个函数或数组。不过,您正在做的是在定义选项对象时调用一个函数。当您在那里调用它时,轴变量不存在。您需要的很简单:

    grid: {
hoverable: true,
clickable: true,
markings: fMarkings
},

fMarkings 是这样的函数:

fMarkings = function(axes){
return arrayOfMarkings
}

关于javascript - float 标记函数,轴未定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25646636/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com