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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to Custom ReDraw Tooltip for Y Series

Thread ID:

Created:

Updated:

Platform:

Replies:

116269 May 7,2014 03:57 AM UTC May 8,2014 05:58 PM UTC WinForms 1
loading
Tags: Chart
Gaurav Chaudhary
Asked On May 7, 2014 03:57 AM UTC

 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.

 


 


 

 


Anandaraj T [Syncfusion]
Replied On 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 + "\nX Value: " + this.chartControl1.Series[ser].Points[point].X + "\nY 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


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;