Customising Tooltips for individual data series

5 posts, 1 answers
  1. Ian
    Ian avatar
    51 posts
    Member since:
    Apr 2009

    Posted 15 Jun 2009 Link to this post

    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?

  2. Answer
    Rusty Udan
    Rusty Udan avatar
    2 posts
    Member since:
    Apr 2009

    Posted 15 Jun 2009 Link to this post

    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,
  3. Ian
    Ian avatar
    51 posts
    Member since:
    Apr 2009

    Posted 16 Jun 2009 Link to this post

    Thanks Rusty. That works great :-)
  4. Rick Glos
    Rick Glos avatar
    70 posts
    Member since:
    Mar 2009

    Posted 13 Dec 2011 Link to this post

    Is this still the recommended way to do this?
  5. Sia
    Sia avatar
    755 posts

    Posted 16 Dec 2011 Link to this post

    Hello Rick Glos,

    Yes, the approach suggested by Rusty Udan is correct.

    Best wishes,
    the Telerik team

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

Back to Top