This is a migrated thread and some comments may be shown as answers.

Customising Tooltips for individual data series

4 Answers 63 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Ian
Top achievements
Rank 1
Ian asked on 15 Jun 2009, 05:34 PM
To customise a tooltip I have the ItemToolTipOpening event I can hook into. However this is a single event set at the chart area level (despite the fact I set the fact I want tooltips at the DataSeries level)

Most of the data, other than the data value itself is set to 0 or null even though I get a DataPoint and DataSeries back in ItemToolTipEventArgs Basically I have no way of knowing which DataSeries triggered the event and so it is impossible to customise different tooltips with text appropriate for different data series.

To give a specific example, I want to customise a different tooltip for each different series in a stacked bar chart.

So if I have three bars stacked A=20, B=10 and C=30 and I want a tooltip that displays "A has a value of 20" or "B has a value of 10" I can use the DataPoint.YValue(ie 10, 20 or 30) to determine which of A, B or C the event has fired for and customise the tooltip accordingly. But this is a kludge that doesn't work if eg both A and B have the same value.  It would be preferable to get something back that gives me the DataSeries index value (eg 0, 1 or 2) for which the event has been fired so I know specifically which data series has triggered the event. It seems pointless to allow turning on tooltips at the dataseries level but then not provide the information at the customisation event point to advise which dataseries wants the customised tooltip.

Is there any way in the event to work around this or ascertain which specific dataseries has fired the event?

Thanks,
Ian 

4 Answers, 1 is accepted

Sort by
0
Accepted
Rusty Udan
Top achievements
Rank 1
answered on 15 Jun 2009, 08:10 PM
Hi Ian,
  You should be able to use the following code to distinguish the correct DataSeries:

private void ItemToolTipOpening(ItemToolTip2D tooltip, ItemToolTipEventArgs e)
{
            if (e != null)
                tooltip.Content = String.Format("{0} has a value of {1}", e.DataSeries.LegendLabel, e.DataPoint.YValue);
}

This assumes that when you populate your DataSeries that you set the appropriate DataSeries.LegendLabel to (A, B, C, etc...).

Hope this helps,
Rusty
0
Ian
Top achievements
Rank 1
answered on 16 Jun 2009, 08:23 AM
Thanks Rusty. That works great :-)
0
Rick Glos
Top achievements
Rank 1
answered on 13 Dec 2011, 06:49 PM
Is this still the recommended way to do this?
0
Sia
Telerik team
answered on 16 Dec 2011, 04:46 PM
Hello Rick Glos,

Yes, the approach suggested by Rusty Udan is correct.

Best wishes,
Sia
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
Chart
Asked by
Ian
Top achievements
Rank 1
Answers by
Rusty Udan
Top achievements
Rank 1
Ian
Top achievements
Rank 1
Rick Glos
Top achievements
Rank 1
Sia
Telerik team
Share this question
or