Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
having trouble updating my legend with values
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Peter  
View profile  
 More options Feb 10 2012, 4:37 pm
From: Peter <peterdsoderl...@gmail.com>
Date: Fri, 10 Feb 2012 13:37:15 -0800 (PST)
Local: Fri, Feb 10 2012 4:37 pm
Subject: having trouble updating my legend with values
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)));
     }


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Emily  
View profile  
 More options Nov 9 2012, 9:29 am
From: Emily <eyo...@jrn.com>
Date: Fri, 9 Nov 2012 06:29:47 -0800 (PST)
Local: Fri, Nov 9 2012 9:29 am
Subject: Re: having trouble updating my legend with values

Can't be sure because I'm new to think but I think the problem is in this
line...

legends.eq(i).text(series.label.replace(/=.*/, "= " + y.toFixed(2)));

The part I highlighted works for the example on Flot because of the
existing text in the legend. You'll want to put what exists in your version
of the legend in that field. It's looking for what part of the legendLabel
to replace.

Here's more on the javascript replace
method: http://www.w3schools.com/jsref/jsref_replace.asp


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »