[英]Tooltip issue on stacked line graph in flot graphs
我正在使用堆积的折线图,但是我遇到悬停工具提示的问题。 有些值为0。我只想忽略0个值点上的工具提示,因为它们会覆盖大于0个值的点。
我试图从数据数组中消除0个值点,但是这样做会使图形无法正确呈现。
请看一下这个:
使用flot.tooltip
插件时,您可以将content
属性设置为一个函数,该函数返回工具提示的字符串,或者在您不希望显示工具提示的情况下返回false(参见文档 ),如下所示:
tooltipOpts: {
content: function (label, x, y, datapoint) {
if (y == 0) {
return false;
}
else {
// change this to get your desired format
return (new Date(x)).toString() + label + x;
}
},
当通过plothover
事件手动生成工具提示时,请在显示工具提示之前检查该值,如下所示:
$("#placeholder").bind("plothover", function (event, pos, item) {
// check if value is zero
if (item && item.datapoint[1] != 0) {
var x = item.datapoint[0].toFixed(2),
y = item.datapoint[1].toFixed(2);
// change this to get your desired format
$("#tooltip").html(x + item.series.label + y)
.css({top: item.pageY + 5, left: item.pageX + 5}).fadeIn(200);
} else {
$("#tooltip").hide();
}
});
我已经分析了代码库,这是我打算进行的更改。 https://github.com/flot/flot/pull/1447/files
@@ -607,7 +607,8 @@ Licensed under the MIT license.
clickable: false,
hoverable: false,
autoHighlight: true, // highlight in case mouse is near
- mouseActiveRadius: 10 // how far the mouse can be away to activate an item
+ mouseActiveRadius: 10, // how far the mouse can be away to activate an item
+ ignoreZeroValuePoints: false
},
interaction: {
redrawOverlayInterval: 1000/60 // time between updates, -1 means in same flow
@@ -2873,8 +2874,11 @@ Licensed under the MIT license.
// use <= to ensure last point takes precedence
// (last generally means on top of)
if (dist < smallestDistance) {
- smallestDistance = dist;
- item = [i, j / ps];
+ jps = j / ps;
+ if(!options.grid.ignoreZeroValuePoints || series[i].data[series[i].datapoints.points.slice(jps * series[i].datapoints.pointsize, (jps + 1) * series[i].datapoints.pointsize)[0]][1] != 0){
+ smallestDistance = dist;
+ item = [i, jps];
+ }
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.