Reputation: 3569
I made a combination of Flot series-toggle sample with Flot tooltip. but I get errors when I have multiple series and hide some of them.
in plothover, pos.y might be undefined if the first chart is hidden. Instead, there might be y1, y2, y3 ... (according to show\hide chart?)
Relevant code:
$("#placeholder").bind("plothover", function (event, pos, item) {
var str = "(" + pos.x.toFixed(2) + ", " + pos.y.toFixed(2) + ")";
$("#hoverdata").text(str);
. . .
Is there a simple function which return pos.y, y1, y2, y3 as array? Or do I need to test each if it is not undefined?
Upvotes: 0
Views: 196
Reputation: 17550
This happens only if you have multiple y-axes, the y1 value is the y-position in relation to the first y-axis, y2 the position on the second y-axis and so on (the y value is always the same as y1).
If one axis is hidden (because all data series which use that axis are hidden) then that value is missing (undefined). But even when all values (y1, y2, y3 ...) are there you need to know which to use for the hovered data point. You get this from
item.series.yaxis.n
and the correct y-position for your point is then
pos['y' + item.series.yaxis.n]
The same holds true for x-axes if you have more than one of them.
Upvotes: 2