We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to Custom ReDraw Tooltip for Y Series

 Need your help urgently.

 Product Used: (Winforms)

Syncfusion Chart 11.3035.0.30

 Requirement:

We need to draw Tooltip on Chart Control series. How can I achieve this?

I do not found any event which support re-draw of Tooltip on Chart control series.

 


 


 

 


1 Reply

AT Anandaraj T Syncfusion Team May 8, 2014 05:58 PM UTC

Hi Gaurav,

Thanks for using Syncfusion products.

Currently, support to customize spacing in chart tooltip is not available. As a workaround solution, we can use “ChartRegionMouseMove” event of chart control to draw customized tooltip for chart.

Please refer the following code snippet to achieve this.

<code>

[CS]

            //Mouse move event for Chart

            this.chartControl1.ChartRegionMouseMove += chartControl1_ChartRegionMouseMove;

 

        //Chart region mouse move event

        void chartControl1_ChartRegionMouseMove(object sender, ChartRegionMouseEventArgs e)

        {

            CurrentPoint=e.Point;

            if (e.Region.IsChartPoint)

            {

                int ser = e.Region.SeriesIndex;

                int point = e.Region.PointIndex;

 

                info.Location = new Point(CurrentPoint.X+5, CurrentPoint.Y+5);

                info.Text = "Series Name: " + this.chartControl1.Series[ser].Name + "X Value: " + this.chartControl1.Series[ser].Points[point].X + "Y Value: " + this.chartControl1.Series[ser].Points[point].YValues[0];

                               

                if (PreviousPoint != Point.Empty && Math.Abs(CurrentPoint.X - PreviousPoint.X) < 2 && Math.Abs(CurrentPoint.Y - PreviousPoint.Y) < 2)

                {

                    this.chartControl1.Refresh();

                    //Drawing customized tooltip in mouse move event of Chart

                    DrawCustomToolTip(info);

                }

                PreviousPoint = CurrentPoint;

                ClearToolTip = true;

            }

            else

                if (ClearToolTip)

                {

                    this.chartControl1.Refresh();

                    ClearToolTip = false;

                }           

        }

 

       //Method to draw custom tooltip

        void DrawCustomToolTip( ToolTipInfo info)

        {

            Graphics gr = this.chartControl1.GetGraphics();

            Pen p=new Pen(info.BorderColor);

            SizeF textSize=gr.MeasureString(info.Text, info.TextFont);

            Rectangle rect = new Rectangle(info.Location.X, info.Location.Y, (int)textSize.Width + info.Spacing, (int)textSize.Height + info.Spacing);

            gr.DrawRectangle(p, rect);

            SolidBrush br = new SolidBrush(info.BackgroundColor);

            gr.FillRectangle(br, rect);

            Point textLocation=new Point(info.Location.X+info.Spacing/2, info.Location.Y+info.Spacing/2);

            gr.DrawString(info.Text, info.TextFont, new SolidBrush(info.FontColor), textLocation);

        }

 

    //Class for storing custom tooltip settings

    public class ToolTipInfo

    {

        public string Text { get; set; }

        public int Spacing { get; set; }

        public Color BackgroundColor { get; set; }

        public Color BorderColor { get; set; }

        public Color FontColor { get; set; }

        public Font TextFont { get; set; }

        public ToolTipInfo() { }

        public Point Location { get; set; }

    }

</code>

For your convenience, we have created a simple sample and it can be downloaded from the following link.

CustomToolTip.zip

Please let us know if you have any concern.

Regards,

Anand


Loader.
Live Chat Icon For mobile
Up arrow icon