Tool tip Pop up on Mouse over on a Chart

5 posts, 0 answers
  1. kiran
    kiran avatar
    36 posts
    Member since:
    May 2008

    Posted 05 Jun 2008 Link to this post

    Hi,

    I need to show a tool tip pop up on mouse over on a chart.

    exact requirement is like:

    i have a Line chart with dates on X-axis and double values on Y-axis.

    In general on mouse over on any chart we will get tool tip which shows the value at that point.

    instead i need to show a pop up  kind of thing (like wise context menu/ Data table which has one column and multiple rows) on mouse over.which should  have 5 different data items which i need to get from XML/DataBase for that particular date where Mouse was currently placed.

    Can any one provide the approach to do this? is this possible with RadControls?
    If so please provide some sample application/ Code.

    Thanks in advance.

    regards,
    kiran





  2. Dwight
    Admin
    Dwight avatar
    475 posts

    Posted 06 Jun 2008 Link to this post

    Hello kiran,

    Unfortunately, there is no MouseOver event for each of the Series' Items, nor such information is included in the RadChart's MouseOver event. You'll have to use the RadChart's event and check all items' regions. Here is a sample code:
    1 public Form1() 
    2
    3     InitializeComponent(); 
    4  
    5     this.radChart1.MouseMove += new MouseEventHandler(radChart1_MouseMove); 
    6
    7  
    8 private void radChart1_MouseMove(object sender, MouseEventArgs e) 
    9
    10     int seriesIndex, itemIndex; 
    11  
    12     if (GetUnderlyingItem(e.X, e.Y, out seriesIndex, out itemIndex)) 
    13     { 
    14         Debug.WriteLine(string.Format("Series[{0}].Items[{1}]", seriesIndex, itemIndex)); 
    15     } 
    16
    17  
    18 private bool GetUnderlyingItem(int x, int y, out int seriesIndex, out int itemIndex) 
    19
    20     for (int i = 0; i < this.radChart1.Series.Count; i++) 
    21     { 
    22         for (int j = 0; j < this.radChart1.Series[i].Items.Count; j++) 
    23         { 
    24             GraphicsPath region = this.radChart1.Series[i].Items[j].ActiveRegion.Region; 
    25             RectangleF bounds = region != null ? region.GetBounds() : RectangleF.Empty; 
    26             if (bounds.Contains(x, y)) 
    27             { 
    28                 seriesIndex = i; 
    29                 itemIndex = j; 
    30                 return true
    31             } 
    32         } 
    33     } 
    34  
    35     seriesIndex = itemIndex = -1; 
    36  
    37     return false
    38

    Note, that in case of irregular shapes the hit testing will be inaccurate as we take the bounding rectangle (see lines 24 & 25). You will need to furhter improve the code for better accuracy.

    Regards,
    Evtim
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for WinForms is Visual Studio 2017 Ready
  4. chandra
    chandra avatar
    21 posts
    Member since:
    Apr 2008

    Posted 20 Jun 2008 Link to this post

    hi,

    We are getting the underlying item of point(X,Y).

    But i want to get the X,Y position of the Item on the chart.

    I want to put all the items X,Y position in an array or list .

    Is there any way to get these things.
    Please share the  sample code.


    Thanks and Regards,
    chandu.
  5. Dwight
    Admin
    Dwight avatar
    475 posts

    Posted 20 Jun 2008 Link to this post

    Hello chandra,

    You cannot obtain the X, Y coordinates of the chart item as each item occupies a region. You can, however, obtain the bounding rectangles of all items on the chart area:
    1 private void radChart1_PrePaint(object sender, EventArgs e) 
    2
    3     List<RectangleF> bounds = GetItemsBounds(); 
    4
    5  
    6 public List<RectangleF> GetItemsBounds() 
    7
    8     return GetItemsBounds(this.radChart1.Series); 
    9
    10  
    11 private static List<RectangleF> GetItemsBounds(ChartSeriesCollection series) 
    12
    13     List<RectangleF> bounds = new List<RectangleF>(); 
    14  
    15     if (series != null
    16     { 
    17         foreach (ChartSeries item in series) 
    18         { 
    19             bounds.AddRange(GetItemsBounds(item)); 
    20         } 
    21     } 
    22  
    23     return bounds; 
    24
    25  
    26 private static List<RectangleF> GetItemsBounds(ChartSeries series) 
    27
    28     List<RectangleF> bounds = new List<RectangleF>(); 
    29      
    30     if (series != null
    31     { 
    32         foreach (ChartSeriesItem item in series.Items) 
    33         { 
    34             GraphicsPath region = item.ActiveRegion.Region; 
    35             RectangleF b = region != null ? region.GetBounds() : RectangleF.Empty; 
    36             bounds.Add(b); 
    37         } 
    38     } 
    39  
    40     return bounds; 
    41


    Regards,
    Evtim
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. chandra
    chandra avatar
    21 posts
    Member since:
    Apr 2008

    Posted 20 Jun 2008 Link to this post

    hi,

    Thanks for your quick reply.

    Actually my requirement is:

    I have drawn a line chart.
    I am drawing a rectangle on a chart after the chart is displayed.

    I want dataitems collection which will come under the boundaries of a  Rectangle.

    My plan is, if i get the dataitems X, Y position then i will check whether the dataitem will fall under the boundaries of a Rectangle.

    Is there any another idea to do this.
    Please give the idea.
    Please share the sample code.


    Thanks and Regards,
    Chandra.
     
Back to Top
UI for WinForms is Visual Studio 2017 Ready