Peter
unread,Feb 10, 2012, 4:37:15 PM2/10/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Flot graphs
I have been reading the example on the FLOT home page and googling for
other examples but I have not yet been able to get my graph to update
the value in the legend with the value of the graph under the mouse.
Here is my code, I am not getting any errors from firebug or the error
console so I am really confused. Could someone please point out my
mistake?
var container = $("#covarianceChartContainer");
var data = [{ data: covariance, label: "T = 0.0" }];
var options = {
crosshair: { mode: "x" },
xaxis:{
mode: "time",
ticks: 6
},
grid: { hoverable: true}
};
var plot = $.plot(container, data, options);
var legends = $("#covarianceChartContainer .legendLabel");
container.bind("plothover", function (event, pos) {
for(i in plot.getData().length){
var series = plot.getData()[i];
var j = 0;
// find the nearest points, x-wise
for (j = 0; j < series.data.length; ++j){
if (series.data[j][0] > pos.x){
break;
}
}
// now interpolate
var y, p1 = series.data[j - 1], p2 = series.data[j];
if (p1 == null)
y = p2[1];
else if (p2 == null)
y = p1[1];
else
y = p1[1] + (p2[1] - p1[1]) * (pos.x - p1[0]) / (p2[0]
- p1[0]);
legends.eq(i).text(series.label.replace(/=.*/, "= " +
y.toFixed(2)));
}
});