Search code examples
c#teechart

How to add tooltips to a Box plot in TeeChart?


As the title says, I am using TeeChart to draw several boxplots within one chart object. Since, the number of boxplots can be quite big, I want to be able to click on a box and have information pertaining to that series to show up as a tooltip.

I am currently trying to do this with a MarksTip but for some reason, when I try to hover over the box, MarksTip will sometimes open and then immediately close (basically being visible for a split second). I have already tried setting the hide delay but it seems to be ignoring that.

Code snippet below:

seriesIndex = 0;

foreach (var seriesData in seriesDataList)
{
    var series = new Box()

    series.UseCustomValues = true;
    series.Box.HorizSize = 5;
    series.Box.Style = PointerStyles.Rectangle;
    series.MildOut.Visible = true;
    series.MildOut.HorizSize = 2;
    series.MildOut.VertSize = 2;
    series.ExtrOut.Visible = true;
    series.ExtrOut.HorizSize = 2;
    series.ExtrOut.VertSize = 2;
    series.LinePen.Visible = _isLineVisible;
    series.Pointer.Pen.Visible = true;
    series.ShowInLegend = false;

    series.Add(seriesIndex, seriesData);

    series.Title = "tooltip text";
    var tooltip = new MarksTip(Chart.Chart)
    {
        Series = series,
        Style = MarksStyles.SeriesTitle,
        HideDelay = 31000,
    };
    Chart.Series.Add(series);

    seriesIndex++;
}

Solution

  • Credit to this other question for pointing me in the right direction.

    I ended up using the GetSeriesMark event to modify the text of a single chart-bound MarksTip instead of creating multiple series-bound `MarksTip

    seriesIndex = 0;
    Chart.Tools.Add(new MarksTip());
    
    foreach (var seriesData in seriesDataList)
    {
        var series = new Box()
    
        series.UseCustomValues = true;
        //Other series appearance stuff
    
        series.Add(seriesIndex, seriesData);
    
        series.Title = "tooltip text";
        series.GetSeriesMark += (s, args) =>
        {
            args.MarkText = s.Title;
        };
        series.Marks.Visible = false;
        Chart.Series.Add(series);    
        seriesIndex++;
    }
    

    One note about this method. The tooltip will only appear when hovering over actual datapoints and not the whole box. Not ideal but at least I can read the tooltip now.