title: vis.js Get Y value in a 2dgraph
body: <p>I'm using vis.js to diplay some dataset like on a 2dgraph :</p>
  
  <pre><code>var data_lat=[
  {x:'2016-02-05T07:58:49.257',y:48.66081132,group:0},
  {x:'2016-02-05T07:58:51.257',y:48.66081132,group:0},
  ...
  </code></pre>
  
  <p>I have put a draggable cursor on that graph with</p>
  
  <pre><code>graph_lat.addCustomTime(time[0].t, '1');
  </code></pre>
  
  <p>and I would ike to display the curent value of y depending of the position of my cursor.</p>
  
  <p>I've looked though vis.js doc but I didn't find anything</p>
  
  <hr>
  
  <p>/<strong>/EDIT TO ANSWER/</strong>/</p>
  
  <p>This is the function i created to get the y value BUT : only for array with only one group in it</p>
  
  <pre><code>function closest (time, arr) {
  var mid, time_mid;
  var lo = 0;
  var hi = arr.length - 1;
  var time_number=moment(time).format('x');
  //console.log(time_number);
  while (hi - lo &gt; 1) {
      mid = Math.floor ((lo + hi) / 2);
      time_mid=moment(arr[mid].x).format('x');
      if (time_mid &lt; time_number) {
          lo = mid;
      } else {
          hi = mid;
      }
  }
  if (time_number - moment(arr[lo].x).format('x') &lt;= moment(arr[hi].x).format('x') - time_number) {
      return arr[lo].y;
  }
  return arr[hi].y;
  </code></pre>
  
  <p>}</p>
  
  <p>and here the one for array with many group (like many <code>y</code> for one <code>x</code> value) like this array :</p>
  
  <pre><code>{x:'2016-02-05T07:58:49.257',y:0,group:8},
  {x:'2016-02-05T07:58:49.257',y:0,group:9},
  {x:'2016-02-05T07:58:49.257',y:0,group:10},
  {x:'2016-02-05T07:58:49.257',y:0,group:11},
  {x:'2016-02-05T07:58:51.257',y:9,group:8},
  {x:'2016-02-05T07:58:51.257',y:6,group:9},
  {x:'2016-02-05T07:58:51.257',y:0,group:10},
  {x:'2016-02-05T07:58:51.257',y:15,group:11},
  {x:'2016-02-05T07:58:53.257',y:9,group:8}
  
  function closest_multi_group (time, arr, groupID) {
  var mid, time_mid;
  var lo = 0;
  var hi = arr.length - 1;
  var time_number=moment(time).format('x');
  //console.log(time_number);
  while (hi - lo &gt; 1) {
      mid = Math.floor ((lo + hi) / 2);
      time_mid=moment(arr[mid].x).format('x');
      if (time_mid &lt; time_number) {
          lo = mid;
      } else {
          hi = mid;
      }
  }
  console.log((time_number - moment(arr[lo].x).format('x'))+'&lt;='+(moment(arr[hi].x).format('x') - time_number));
  if (time_number - moment(arr[lo].x).format('x') &lt;= moment(arr[hi].x).format('x') - time_number) {
      console.log(arr[lo]);
  
      if(arr[lo+1].group &lt; arr[lo].group){
          while(arr[lo].group!=groupID){
  
              lo--;
              console.log('lo-- '+lo);
          }
      }
      else{
          while(arr[lo].group!=groupID){
  
              lo++;
              console.log('lo++ '+lo);
          }
      }
      return arr[lo].y;
  }
  
  if(arr[hi-1].group &gt; arr[hi].group){
      console.log(arr[hi]);
      while(arr[hi].group!=groupID){
  
          hi++;
          console.log('hi++ '+hi);
      }
  }
  else{
      console.log(arr[hi]);
      while(arr[hi].group!=groupID){
  
          hi--;
          console.log('hi-- '+hi);
      }
  }
  return arr[hi].y;
  }
  </code></pre>