How can I get the crosshairs position in a xamWebDataChart. I miss a function or property like xamWebChart.Crosshairs.GraphX.
Some of the bits you need to do this elegantly are not part of the public API of the control in the initial release. You can, however, write some additional application code to get it done:
Subscribe to the PropertyUpdated event of the DataChart ->
private void theChart_PropertyUpdated( object sender, Infragistics.Controls.Charts.PropertyUpdatedEventArgs e) { if (e.PropertyName == "CrosshairPoint") { if (e.NewValue != null && e.NewValue is Point) { //get the relevant axes. CategoryXAxis x = theChart.Axes.First((a) => a is CategoryXAxis) as CategoryXAxis; NumericYAxis y = theChart.Axes.First((a) => a is NumericYAxis) as NumericYAxis; //determine the series viewport. Rect viewportRect = GetViewportRect( theChart.Series[0], x, y); Point p = (Point)e.NewValue; double left; double right; double top; double bottom; GetInViewAxisBounds(x, y, viewportRect, out left, out right, out top, out bottom); //get crosshair window values. double windowX = (p.X - theChart.WindowRect.Left) / theChart.WindowRect.Width; double windowY = (p.Y - theChart.WindowRect.Top) / theChart.WindowRect.Height; //interpolate axis values. double xAxisValue = left + (windowX * (right - left)); double yAxisValue = top + (windowY * (bottom - top)); if (!double.IsNaN(xAxisValue) && !double.IsInfinity(xAxisValue)) { XValue = xAxisValue; } if (!double.IsNaN(yAxisValue) && !double.IsInfinity(yAxisValue)) { YValue = yAxisValue; } } } } private void GetInViewAxisBounds( CategoryXAxis x, NumericYAxis y, Rect viewportRect, out double left, out double right, out double top, out double bottom) { left = x.GetUnscaledValue( viewportRect.Left, theChart.WindowRect, viewportRect); right = x.GetUnscaledValue( viewportRect.Right, theChart.WindowRect, viewportRect); top = y.GetUnscaledValue( viewportRect.Top, theChart.WindowRect, viewportRect); bottom = y.GetUnscaledValue( viewportRect.Bottom, theChart.WindowRect, viewportRect); } private Rect GetViewportRect( Series target, CategoryXAxis x, NumericYAxis y) { double top = y.TransformToVisual(target) .Transform(new Point(0, 0)).Y; double bottom = y.TransformToVisual(target) .Transform(new Point(0, y.ActualHeight)).Y; double left = x.TransformToVisual(target) .Transform(new Point(0, 0)).X; double right = x.TransformToVisual(target) .Transform(new Point(x.ActualWidth, 0)).X; double width = right - left; double height = bottom - top; if (width > 0.0 && height > 0.0) { return new Rect(left, top, width, height); } return Rect.Empty; }
-Graham
Graham,
We want to display time series values at the datachart and using the Crosshairs as selection method for the end user to provide detailed data about the data behind. We will get the data behind the selection at the LayerCursorMouseMove-event, but the e.Row-property of the event-arguments is null when no value for the current selected x-axis value is available at the layer. When we got a null-value we want to interpolate the values (right and left value of the selection) in relation to the cursor position. We've not seen a possiblity to get the cursors x-axis coordinates
Hans,
That functionality isn't present in the CTP version of the chart. Could you describe your use case as this will be helpful for our testing.
Thanks,
Graham