This is a migrated thread and some comments may be shown as answers.

Tool tip Pop up on Mouse over on a Chart

4 Answers 64 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
kiran
Top achievements
Rank 1
kiran asked on 05 Jun 2008, 01:14 PM
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





4 Answers, 1 is accepted

Sort by
0
Dwight
Telerik team
answered on 06 Jun 2008, 06:50 AM
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:
public Form1() 
    InitializeComponent(); 
 
    this.radChart1.MouseMove += new MouseEventHandler(radChart1_MouseMove); 
 
private void radChart1_MouseMove(object sender, MouseEventArgs e) 
    int seriesIndex, itemIndex; 
 
    if (GetUnderlyingItem(e.X, e.Y, out seriesIndex, out itemIndex)) 
    { 
        Debug.WriteLine(string.Format("Series[{0}].Items[{1}]", seriesIndex, itemIndex)); 
    } 
 
private bool GetUnderlyingItem(int x, int y, out int seriesIndex, out int itemIndex) 
    for (int i = 0; i < this.radChart1.Series.Count; i++) 
    { 
        for (int j = 0; j < this.radChart1.Series[i].Items.Count; j++) 
        { 
            GraphicsPath region = this.radChart1.Series[i].Items[j].ActiveRegion.Region; 
            RectangleF bounds = region != null ? region.GetBounds() : RectangleF.Empty; 
            if (bounds.Contains(x, y)) 
            { 
                seriesIndex = i; 
                itemIndex = j; 
                return true
            } 
        } 
    } 
 
    seriesIndex = itemIndex = -1; 
 
    return false

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
0
chandra
Top achievements
Rank 1
answered on 20 Jun 2008, 05:57 AM
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.
0
Dwight
Telerik team
answered on 20 Jun 2008, 08:53 AM
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:
private void radChart1_PrePaint(object sender, EventArgs e) 
    List<RectangleF> bounds = GetItemsBounds(); 
 
public List<RectangleF> GetItemsBounds() 
    return GetItemsBounds(this.radChart1.Series); 
 
private static List<RectangleF> GetItemsBounds(ChartSeriesCollection series) 
    List<RectangleF> bounds = new List<RectangleF>(); 
 
    if (series != null
    { 
        foreach (ChartSeries item in series) 
        { 
            bounds.AddRange(GetItemsBounds(item)); 
        } 
    } 
 
    return bounds; 
 
private static List<RectangleF> GetItemsBounds(ChartSeries series) 
    List<RectangleF> bounds = new List<RectangleF>(); 
     
    if (series != null
    { 
        foreach (ChartSeriesItem item in series.Items) 
        { 
            GraphicsPath region = item.ActiveRegion.Region; 
            RectangleF b = region != null ? region.GetBounds() : RectangleF.Empty; 
            bounds.Add(b); 
        } 
    } 
 
    return bounds; 


Regards,
Evtim
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
chandra
Top achievements
Rank 1
answered on 20 Jun 2008, 11:50 AM
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.
 
Tags
Treeview
Asked by
kiran
Top achievements
Rank 1
Answers by
Dwight
Telerik team
chandra
Top achievements
Rank 1
Share this question
or