用Flot识别悬停点?

Aid*_*anc 2 javascript jquery charts flot

希望这个问题不会太混乱或长,我正在使用Flot示例,特别是这个.

我正在使用flot将我收集的一些数据绘制成Scatter图表.我正在使用以下功能...

function genScatter(){
    var no = getSelectedRepeat();
    $.get("getPages.json",{rid: no},function(data){
        var d1 = [];
        $.each(data,function(i,obj){
            d1.push([obj.queries,obj.count,{url: obj.url}]);
        })
        $.plot($("#scatter"), [ { label: "Pages",
            data: d1, 
            lines:{show: false},
            points:{show: true}}],{
            xaxis:{min: 1},
            grid:{ hoverable: true}
        });
  });

}
Run Code Online (Sandbox Code Playgroud)

我的代码生成带有各种点的散点图.当我将鼠标悬停在一个点上时,以下监听器被激活...

$("#scatter").bind("plothover", function (event, pos, item) {
$("#x").text(pos.x.toFixed(2));
$("#y").text(pos.y.toFixed(2));
    if (item) {
        if (previousPoint != item.dataIndex) {
            previousPoint = item.dataIndex;

            $("#tooltip").remove();
            var x = item.datapoint[0].toFixed(2),
                y = item.datapoint[1].toFixed(2);

            /*this would be the line where I extract
             the url and forward it to showToolTip.*/
            showTooltip(item.pageX, item.pageY,
                        item.series.label  + ": " + y);
        }
    }
    else {
        $("#tooltip").remove();
        previousPoint = null;            
    }

});
Run Code Online (Sandbox Code Playgroud)

在哪里showTooltip定义是......

function showTooltip(x, y, contents) {
   $('<div id="tooltip">' + contents + '</div>').css( {
        position: 'absolute',
        display: 'none',
        top: y + 5,
        left: x + 5,
        border: '1px solid #fdd',
        padding: '2px',
        'background-color': '#fee',
        opacity: 0.80
    }).appendTo("body").fadeIn(200);
}
Run Code Online (Sandbox Code Playgroud)

基本上,当我将鼠标悬停在一个点上时,我想渲染用于url添加点的值,d1但是我无法进行,因为item对象不会仅返回x url内部item.datapoint,返回点的y值.url包含item在图item.data中的所有其他点的数组中但位于数组中.

我的问题是,要么从列出的数组中唯一地识别点,要么item.data强制flot包含url在内,item.datapoint是否有办法获得url相应的点?

Mar*_*ark 6

如果你定义了这样的数据结构,那么你应该能够在你的plothover回调中获取url(例如这里):

item.series.data[item.dataIndex][2].url
Run Code Online (Sandbox Code Playgroud)