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);
    }
}

 

 

 

 

转载于:https://www.cnblogs.com/zany-hui/articles/3184937.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值