希望这个问题不会太混乱或太长,我正在使用Flot示例,特别是this one.
我正在使用flot将我收集到的一些数据绘制成散点图。我使用以下函数来完成此操作...
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}
});
});
}我的代码生成了一个包含多个点的散点图。当我将鼠标悬停在一个点上时,下面的监听器就会被激活...
$("#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;
}
});定义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);
}基本上,当鼠标悬停在某个点上时,我希望将添加了该点的url的值呈现给d1,但我无法做到这一点,因为item对象在item.datapoint中不返回url,只返回这些点的x,y值。url包含在item中,但在item.data下,与图中的所有其他点在一个数组中。
我的问题是,无论是从item.data中列出的数组中唯一地确定点,还是强制flot在item.datapoint中包含url,有没有办法让url到达相应的点?
发布于 2012-02-06 01:03:55
如果你这样定义你的数据结构,那么你应该能够在你的plothover回调中获得url (示例here):
item.series.data[item.dataIndex][2].urlhttps://stackoverflow.com/questions/9150964
复制相似问题