1

I have a linechart here: http://jsbin.com/ugexag/1

You can see in the jsbin, when you hover over one 'column' the data for each line appears in a tooltip via the hoverColumn() function. I would love to find a way to get the tooltip to appear only when an individual data point is hovered over. I don't see anything about this in the gRaphael docs.

1
  • I've achieved the desired result by very slightly offsetting the plot point of each line, but it's very fidgety. If I offset any further, it is visually noticeable that the plots are offset, and looks terrible. Perhaps offsetting further, then repositioning is the secret, but not sure yet how to accomplish that. jsbin.com/ugexag/2 Sep 20, 2012 at 2:08

1 Answer 1

2

There's kind of an example of this in the bottom right quadrant of the linechart demo. I'l look at it later today and update here with what I find. I suspect hoverColumn isn't used, or is used creatively, because when I used it, the y I got for the hover event was the average of all y values on the x column.

Update: After looking at it, I found what you found, the trick was that only one of the demo columns lined up in both lines. If you're charting something per year, your year column is definitely going to recur on all lines. So this isn't too handy.

What I tested was (in a console at the linechart demo linked):

var r = Raphael("holder");
var lines = r.linechart(330,250,300,220,[
   [ 1, 2, 3, 4, 5, 6, 7],[ 2, 3, 4, 5, 6, 7, 8],[9,10]
  ],[
   [10,10,10,10,10,10,10],[20,20,20,20,20,20,20],[5,25]
  ],{nostroke:false, axis:"0 0 1 1", symbol: "circle", smooth: true});
lines.hoverColumn(function(){
    this.tags=r.set();
    for(var i=0;i<this.y.length;i++){
      this.tags.push(r.tag(this.x,this.y[i],this.values[i],160,10).insertBefore(this));
    }
  }, function(){
    this.tags && this.tags.remove();
  });

Which at least demonstrates the problem. The problem does indeed lie with the hoverColumn and the documentation. It isn't mentioned that hover actually has mostly the same this information passed to it. So you can rewrite the last statement as:

lines.hover(function({
  this.tags=r.set();
  this.tags.push(r.tag(this.x,this.y,this.value,160,10).insertBefore(this));
 }, function(){
  this.tags && this.tags.remove();
 });

Notice that value is now singular and takes no index, nor does y.
Lastly you can further simplify it by removing the use of a set():

lines.hover(function(){
  this.tag = r.tag(this.x,this.y,this.value,160,10).insertBefore(this);
 }, function(){
  this.tag && this.tag.remove();
 });
3
  • Yep, that's exactly where i figured out how to add tags in the first place :) If you notice in that example, the second to last 'tag' is actually two tags at once, as they are one the same vertical axis. All of my data points will be on the same vertical axis, so that will make things tricky. Thanks for your answer! Sep 29, 2012 at 3:34
  • @Unfortunately I have a fix that uses hover instead of hoverColumn but after looking into this and finding that the range on the axis, the markings on the axis, and grid lines aren't configurable without customizing gRaphaël, I'm going to suggest you look at Google Chart Tools developers.google.com/chart/interactive/docs/roles#tooltiprole
    – dlamblin
    Sep 29, 2012 at 6:07
  • While I'm not particularly worried about fiddling with the source to make this work, I do think in the end I will look for another library. Currently I'm leaning towards d3. For now though I'll continue with g.Raphael.js and omit the tags for the MVP version of my chart. Thanks for your help! Sep 29, 2012 at 19:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.