Telerik chart for silverlight Get chart coordinates for mouse position

You can get the PlotArea in the ChartArea.Loaded event by the extension methodChildrenOfType<ClipPanel>(). In order to use this extension, you need to include namespace reference to Telerik.Windows.Controls. After that you can attach MouseEnter and MouseLeave handlers to the PlotArea. For example:

 

private void ChartArea_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
    Panel plotArea =
        this.radChart.DefaultView.ChartArea.ChildrenOfType<ClipPanel>().FirstOrDefault() as Panel;
    if (plotArea != null)
    {
        plotArea.MouseEnter += content_MouseEnter;
        plotArea.MouseLeave += content_MouseLeave;
    }
}

 

In the Mouse events you can get the physical coordinates of the mouse according to the PlotArea. You can also convert these physical units to data units by the Axis exposed methodConvertPhysicalUnitsToData(physicalUnit). For example:

 

public void content_MouseEnter(object sender, MouseEventArgs e)
{
    Panel plotArea = sender as Panel;
    if (plotArea != null)
    {
        Point physicalPosition = e.GetPosition(plotArea);
 
        ChartArea chartArea = this.radChart.DefaultView.ChartArea;
        double x = chartArea.AxisX.ConvertPhysicalUnitsToData(physicalPosition.X);
        double y = chartArea.AxisY.ConvertPhysicalUnitsToData(physicalPosition.Y);
    }
}

 

 

 

 

posted @ 2013-07-11 20:09  zhh  阅读(316)  评论(0编辑  收藏  举报