Flot Stacked Bar Chart and displaying bar values on mouse over

后端 未结 4 734
再見小時候
再見小時候 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:04

    The code above caused redraw-issues for me. Here is an improved code:

    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, item.series.label + " " + y.toFixed(0) );
            }
        }
        else {
            $("#tooltip").remove();
            previousPoint = [0,0,0];
        }
    });
    

提交回复
热议问题