Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
75
HitText's XValue and YValue incorrect after chart resizes?
posted

I'm plotting X-Y data using ScatterLine series in a XamChart.

I'm using the XamChart.MouseMove to display the X-Y values in a couple text boxes as the user mouses over the chart. Something like this:

void OnChartMouseMove(object sender, MouseEventArgs e)
{
    var args = chart.HitTest(e);
    var x = args.XValue;
    var y = args.YValue;

    XValueTextBlock.Text = String.Format("X: {0:G5}", x);
    YValueTextBlock.Text = String.Format("Y: {0:G5}", y);
}

Everything works well until the user changes the application window size, resulting in a resized XamChart. After that, the values of HitTestArgs.XValue and HitTestArgs.YValue are incorrect.

Has anyone else seen this problem? Anyone know how to work around?

Parents
  • 75
    posted

    This sample illustrates the problem. When you run it., the window starts out at 300 x 300 and the values in the textblock are correct. If you maximize the Window and mouse over the chart, the values are incorrect.

    <Window x:Class="HitTestTest.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ig="clr-namespace:Infragistics.Windows.Chart;assembly=Infragistics3.Wpf.Chart.v8.2"
        Title="Window1" Height="300" Width="300">
        <DockPanel>
            <TextBlock DockPanel.Dock="Bottom" x:Name="textBlock" TextAlignment="Center" />
            <ig:XamChart x:Name="xamChart" MouseMove="xamChart_MouseMove">
                <ig:XamChart.Series>
                    <ig:Series x:Name="xamSeries" ChartType="ScatterLine" DataMapping="ValueX=X;ValueY=Y" />
                </ig:XamChart.Series>
            </ig:XamChart>
        </DockPanel>
    </Window>

    using System;
    using System.Windows;
    using System.Windows.Input;

    namespace HitTestTest
    {
        public partial class Window1 : Window
        {
            public Window1()
            {
                InitializeComponent();

                this.Loaded += delegate
                {
                    xamSeries.DataSource = new Point[]
                    {
                        new Point { X = 0, Y = 0 },
                        new Point { X = 10, Y = 10},
                    };
                };
            }

            private void xamChart_MouseMove(object sender, MouseEventArgs e)
            {
                var args = xamChart.HitTest(e);
                textBlock.Text = String.Format("({0:0.0},{1:0.0})",
                    args.XValue, args.YValue);
            }
        }
    }
     

Reply Children