views:

131

answers:

1

Flex charts, like AreaChart, have wonderful built-in support for displaying data "tool tips" when a user hovers over a point supplied in the data of a graph. You can hover over any of the bar graph examples on this page for a demonstration.

I have a graph situation where I optionally draw in some dots as reference points on CartesianDataCanvases supplied to my AreaChart through it's <mx:annotationElements> and <mx:backgroundElements> tags. I would like to have the same hover data-tip functionality that the AreaChart has, but applied to these dots. Does anyone know how to accomplish this, or if it is even possible?

I realize that I am just drawing on canvas, and that no actual dataProvider supports these dots, but if there was a way to supply the CartesianDataCanvas with an array of data values or something to that effect, that would be great!

+1  A: 

Having seen your other post, I assume you are drawing dots using cdc.graphics. In that case, it is not easy to add hover text to them. Create a class that extends UIComponent, override the updateDisplayList method and do the drawing inside that. Now you can easily add mouse over text using the dot.toolTip property.

//Dot.as
package 
{
  public class Dot 
  {
    override protected function updateDisplayList(unscaledWidth:Number, 
        unscaledHeight:Number):void 
    {
      this.graphics.lineStyle(1);
      this.graphics.drawCircle(0, 0, 5);
    }
}

//... later:
var dot:Dot = new Dot();
dot.x = xValue;
dot.y = yValue;
dot.toolTip = "Hover Text";
cdc.addChild(dot);
Amarghosh
Amarghosh, just wanted to say thanks for your diligence in following up on both of my questions. Your assistance is very much appreciated!
Impirator
I finally got a chance to try this out (work's been busy), and this is almost perfect. However, it turns out that adding to a data canvas (like `CartesianDataCanvas`) prefers `canvas.addDataChild(child, [left, top, right, bottom, hCenter, vCenter])`. Would you mind editing your post to change `cdc.addChild` to `cdc.addDataChild`? Thanks, Amarghosh!
Impirator
Oh! It's also a good idea (I'm told) to call `super.updateDisplayList(unscaledWidth,unscaledHeight);` as the first line when overriding this method. And `public class Dot` needs *`extends UIComponent`*.
Impirator