I see some documentation on how to add vertical or horizontal crosshairs independently to the xamwebchart but it appears that this ability is not available to the xamdatachart. Is this true or have I missed something? Is there a way I can hide the horizontal crosshair on the xamdatachart? If not, what is the functional diffeerence in the xamdatachart and the xamwebchart besides the ability to handle a lot more data points? What is the limit where you would recommend moving to the datachart?
Thanks,Mike
Mike,
Independent control of the visibility of the crosshairs is not currently a feature of the XamDataChart. Ideally there would be no missing features migrating between XamWebChart and XamDataChart but there are currently some missing due to scheduling constraints, most notably there are some series types available in XamWebChart that are not currently available in XamDataChart.
That being said there are lots of new features in XamDataChart that aren't present in XamWebChart, above and beyond all the performance improvements. For example, there are no longer any restrictions on which series types can share the same plotting area, axes support inversion, unlimited number of axes are supported, multiple charts can syncrhonize their panning and zooming, labels, legends, tooltips support rich content, etc. XamDataChart also supports some new series types that XamWebChart does not currently support.
I would suggest contacting our product management and they may be able to give you a more detailed and sanctioned view into the strategy for these in the coming releases. Its possible that the marketing info on the website is the best publishable info in this respect, however.
In the meantime, here's a nifty behavior that can help you hide the horizontal or vertical crosshair for a chart:
This is how to attach the behavior to the chart:
<ig:XamDataChart Name="xamDataChart1" CrosshairVisibility="Visible"> <local:ChartBehaviors.CrosshairHiding> <local:CrosshairHidingBehavior HideHorizontalCrossHair="True" /> </local:ChartBehaviors.CrosshairHiding> </ig:XamDataChart>
Here is the supporting code:
public class ChartBehaviors : DependencyObject { public static readonly DependencyProperty CrosshairHidingProperty = DependencyProperty.RegisterAttached("CrosshairHiding", typeof(CrosshairHidingBehavior), typeof(ChartBehaviors), new PropertyMetadata(null, (o, e) => CrosshairHidingChanged( o as XamDataChart, e.OldValue as CrosshairHidingBehavior, e.NewValue as CrosshairHidingBehavior))); public static CrosshairHidingBehavior GetCrosshairHiding( DependencyObject target) { return target.GetValue(CrosshairHidingProperty) as CrosshairHidingBehavior; } public static void SetCrosshairHiding( DependencyObject target, CrosshairHidingBehavior behavior) { target.SetValue(CrosshairHidingProperty, behavior); } private static void CrosshairHidingChanged( XamDataChart chart, CrosshairHidingBehavior oldValue, CrosshairHidingBehavior newValue) { if (chart == null) { return; } if (oldValue != null) { oldValue.OnDetach(chart); } if (newValue != null) { newValue.OnAttach(chart); } } } public class CrosshairHidingBehavior { private Style _invisibleStyle; public CrosshairHidingBehavior() { _invisibleStyle = new Style(typeof(Line)); _invisibleStyle.Setters.Add( new Setter(Shape.StrokeThicknessProperty, 0)); } public bool HideHorizontalCrossHair { get; set; } public bool HideVerticalCrossHair { get; set; } public void OnAttach(XamDataChart chart) { chart.MouseEnter += Chart_MouseEnter; } public void OnDetach(XamDataChart chart) { chart.MouseEnter -= Chart_MouseEnter; MakeVisible(chart, _vertical); MakeVisible(chart, _horizontal); _vertical = null; _horizontal = null; _first = true; } private bool _first = true; private Line _vertical; private Line _horizontal; private void MakeInvisible( XamDataChart chart, Line crosshairLine) { crosshairLine.Style = _invisibleStyle; } private void MakeVisible( XamDataChart chart, Line crosshairLine) { if (chart == null || crosshairLine == null) { return; } crosshairLine.Style = chart.CrosshairLineStyle; } void Chart_MouseEnter(object sender, MouseEventArgs e) { XamDataChart chart = sender as XamDataChart; if (_first && chart != null) { _first = false; var crosshairs = from line in chart.VisualDescendants() where line is Line && (line as Line).Style == chart.CrosshairLineStyle select line as Line; List<Line> lines = crosshairs.ToList(); if (lines[0].X1 == lines[0].X2) { _vertical = lines[0]; _horizontal = lines[1]; } else { _vertical = lines[1]; _horizontal = lines[0]; } if (HideHorizontalCrossHair) { MakeInvisible(chart, _horizontal); } if (HideVerticalCrossHair) { MakeInvisible(chart, _vertical); } } } } public static class Extensions { public static IEnumerable<DependencyObject> VisualDescendants( this DependencyObject current) { yield return current; for (int i = 0; i < VisualTreeHelper.GetChildrenCount(current); i++) { DependencyObject child = VisualTreeHelper.GetChild(current, i); foreach ( DependencyObject sub in child.VisualDescendants()) { yield return sub; } } } }
If you have any more questions, let me know. Hope this helps!-Graham
Any updates for this?
- Kataria
Hello Kataria,
The solution that Graham provided is the one that you can use to achieve the functionality you want. Here you can see how this approach works in a sample:
http://samples.infragistics.com/sllob/RunSamples.aspx?cn=data-chart#/data-chart/chart-crosshairs
Hope this helps you.