Flot Stacked Bar Chart and displaying bar values on mouse over

后端 未结 4 732
再見小時候
再見小時候 2021-02-04 01:28

I\'m trying to understand the tooltip functionality of Flot but not really getting my head around it!

I am trying to achieve a tooltip that displays the label and value

4条回答
  •  野性不改
    2021-02-04 02:11

    This is the same as Thomas above, except that I shifted the tooltip up to prevent it blocking the hover action.

    var previousPoint = [0,0,0];
    $("#regionsChart").bind("plothover", function (event, pos, item) {
        if (item) {
            if (previousPoint[0] != item.datapoint[0]
                || previousPoint[1] != item.datapoint[1]
                || previousPoint[2] != item.datapoint[2]
            ) {
                previousPoint = item.datapoint;
    
                $("#tooltip").remove();
                var x = item.datapoint[0],
                    y = item.datapoint[1] - item.datapoint[2];
    
                showTooltip(item.pageX, item.pageY - 35, item.series.label + " " + y.toFixed(0) );
            }
        }
        else {
            $("#tooltip").remove();
            previousPoint = [0,0,0];
        }
    });

提交回复
热议问题