【发布时间】:2014-09-19 22:11:56
【问题描述】:
我有一个使用 JQuery Flot 制作的条形图。我希望当我将鼠标移过某个栏时,显示一个工具提示。
看看我在条形图选项中所做的一些定义。
grid: {
hoverable: true,
borderWidth: 0,
color: '#838383',
clickable: true
}
当我加载所有数据并绘制图表时,我将plothover 事件绑定为如下所示
$(dataParameters.containerSuccess).bind("plothover", self.funcaoPassarMouse);
我的plothover 函数
self.funcaoPassarMouse = function (event, pos, item) {
if (item) {
if (previousPoint != item.dataIndex) {
previousPoint = item.dataIndex;
$("#tooltip").remove();
var x = item.datapoint[0].toFixed(2),
y = self.CommaFormatted(item.datapoint[1].toFixed(2));
var mes = self.ObtemMes(item);
self.exibirTooltip(item.pageX, item.pageY, "R$ " + y + " em " + mes);
}
} else {
$("#tooltip").remove();
previousPoint = null;
}
}
我有很多使用 JQuery Flot 的图表,并且在所有图表中,使用此功能的 plothover 事件运行良好,但在条形图中除外。
在条形图中,我看到item 参数带有null 值,我不知道为什么。
谁能帮帮我?
【问题讨论】:
-
你能制作一个小提琴(或者更好的堆栈 sn-p)来证明你的问题吗?
-
@MattBurland 当然,给我一些时间,我会把小提琴的链接放在这里
-
在这里工作正常:jsfiddle.net/mwyeck3q/1
-
@MattBurland 看看jsfiddle.net/7snkmshf/1
-
我认为问题在于
time作为轴设置与条形图交互的方式(注意细条)。如果您将轴的类型更改为“类别”,那么您会得到正确检测的粗条(但会丢失时间格式)。另请注意,如果您将鼠标悬停在图表边缘,它确实会检测到第一个和最后一个柱,这很奇怪。
标签: jquery jquery-plugins