Tooltips for annotations

Apr 23, 2013 at 2:39 PM
Hello all,

first of all: many thanks to the OxyPlot author(s). This is really great work !!!

My question:

in my plot I show a time series. For certain instants of time I show a vertical line annotation and additionally a rectangular annotation like a flag which contains a number. The number corresponds to an event and I would like to show additional information for the flag as a tooltip. Is it possible to show something like a tooltip when the mouse hovers over the annotation?

Thanks for any ideas.
Nicolas
Apr 24, 2013 at 4:48 AM
I join to both: question and thanks to OxyPlot authors! (Best chart library for .net)

I have the same problem. Chart series with rectangle (annotation) corresponding time interval, tooltip is needed to show additional information.

May be you give clue on source code how to implement this functionality (I ready send patch if it would usefull)
Coordinator
Apr 24, 2013 at 9:16 AM
The tooltips should be easy to implement for WPF and Silverlight, but it may be more difficult on the other platforms. I have not decided whether to make solution where OxyPlot does most of the work related to the tooltips (hit testing) or if it should rely on the different implementations.
The original idea was to use IRenderContext.SetToolTip to set the tooltip on all following graphics elements. It is implemented for WPF in ShapesRenderContext.ApplyToolTip
Apr 24, 2013 at 9:33 AM
Hello and thanks for the reply. I didn't expect that it is so easy :-) at least for WPF. I wrote my own Annotation class for other reasons anyway, so here is part of the class that shows setting the tooltip:
public class FlagAnnotation : Annotation
{
    ...

    public override void Render(IRenderContext rc, PlotModel model)
    {
        ...
        OxyPlot.Wpf.ShapesRenderContext src = rc as OxyPlot.Wpf.ShapesRenderContext;

        src.SetToolTip("This ist the tooltip");

        OxyRect rect = new OxyRect();
        ...
        
        rc.DrawRectangle(rect, OxyColors.LightBlue, OxyColors.Black);
        ...            
    }
}
Jul 8, 2014 at 10:11 AM
Edited Jul 8, 2014 at 10:11 AM
Thanks for the Sample! I build myself a PointAnnotation with tooltips enabled out of that:

With default ShapesRenderContext tooltip text only applies to text and images.
   public class TooltipPointAnnotation : PointAnnotation {
        /// <summary>
        ///     gets or sets the tooltip text
        /// </summary>
        public string Tooltip { get; set; }

        public override void Render(IRenderContext rc, PlotModel model) {

            /*  get render context */
            ShapesRenderContext src = rc as ShapesRenderContext;

            /* set tooltip to render context if it exists */
            if (src != null) {
                src.SetToolTip(Tooltip);
            }

            /* draw elements the tooltip may apply to (text and images) */
            base.Render(rc, model);
        }
    }
Given the above I get a nice point annotation with an tooltip on the annotation text.
Coordinator
Jul 10, 2014 at 10:36 AM
Edited Jul 10, 2014 at 10:37 AM
I think the ToolTip property should be added to the PlotElement class and set when rendering all elements. Some refactoring should also be done - e.g. a new virtual Render method on the PlotElement class!
I have added https://oxyplot.codeplex.com/workitem/10230