Monday, January 5, 2009

datatipfunction in a linechart

To customize the datatip in a linechart in flex you need to use the datatipfunction property that refers to a function. This function must return a string and take a parameter of type HitData. To get the current VALUE of the line point you're mousing over you need to use LineSeriesItem(hitData.chartItem).yValue - I found this difficult to find out at first.

Here's an example:

private function lcDataTipFunction(hitData:HitData):String
{
var s:String;
s = LineSeries(hitData.element).displayName + "\n";
s += LineSeriesItem(hitData.chartItem).yValue + "\n";
s += hitData.item.Day + " at " + hitData.item.Time;
return s;
}

5 comments:

tomgutz said...

I was looking for some answers on the net for some flex challenges and stumbled on your page. In which I found out something else....You are the first girl i have seen using flex, very interesting indeed.

nice portfolio site as well.

Mohito said...

you are my Man Friday.. thanks for the tip.. i have been struggling long on the dataTipFunction.

Thanks

farid valipour said...

Dear Angel

Thank you for your very nice code about datatipfunction in linechart and friendly you are very cute.

BR
Farid Valipour

Lombardi said...

Thank you very much.
Canadians rule!

Anonymous said...

Very helpful post, thank you.

Just to add, following imports are needed

import mx.charts.HitData;
import mx.charts.series.items.LineSeriesItem;

Also to note, dataTipFunction is declared under the Chart, not the line series.

- James S