I'm trying to set up some cross hairs showing the x, y values at the mouse cursor, but on barcharts I don't get the same hittest values as on the axis label.How would I go about doing this correctly, should I treat bar charts differently?
i'm not sure why bar charts would be any different from other charts, but i'm not sure because i don't fully understand how you've implemented crosshairs. could you post some sample code?
The crosshairs aren't important, I need the hittest's XValue and YValue to make sense.
I've attached a screenshot of two charts, with the only difference between thembeing one is of charttype 'Column' and the other of 'Bar'.
I've plotted som X Y values from the hittest.XValue and hittest.YValue functions, as you can see the xy valueson the bar chart doesn't make sense.
Here's the code I used
Private Sub XamChart1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseEventArgs) Handles XamChart1.MouseDown Dim h As Infragistics.Windows.Chart.HitTestArgs = XamChart1.HitTest(e) Dim x As Double = e.MouseDevice.GetPosition(LayoutRoot).X - 5 Dim y As Double = e.MouseDevice.GetPosition(LayoutRoot).Y - 10 Dim lbl As New Label lbl.Content = "<- X:" & Math.Round(h.XValue, 2) & " - Y:" & Math.Round(h.YValue, 2) lbl.Margin = New Thickness(x, y, 0, 0) LayoutRoot.Children.Insert(0, lbl) End Sub Private Sub Bind() Dim ds As New System.Data.DataSet ds.ReadXml("C:\TestXMLBinding\TestXMLBinding\Data\ScatterplotData.xml") Dim axisX As New Infragistics.Windows.Chart.Axis axisX.AxisType = Infragistics.Windows.Chart.AxisType.PrimaryX axisX.Label.Format = "{0:n3}" Name = "X" XamChart1.Axes.Add(axisX) Dim axisY As New Infragistics.Windows.Chart.Axis axisY.AxisType = Infragistics.Windows.Chart.AxisType.PrimaryY axisY.Label.Format = "{0:n1}" Name = "Y" XamChart1.Axes.Add(axisY) Dim s As Infragistics.Windows.Chart.Series = New Infragistics.Windows.Chart.Series s.DataSource = ds.Tables(0) s.DataMapping = "label=x;value=y" s.ChartType = Infragistics.Windows.Chart.ChartType.Bar s.AxisX = "X" s.AxisY = "Y" XamChart1.Series.Add(s) End Sub
Private Sub XamChart1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseEventArgs) Handles XamChart1.MouseDown Dim h As Infragistics.Windows.Chart.HitTestArgs = XamChart1.HitTest(e) Dim x As Double = e.MouseDevice.GetPosition(LayoutRoot).X - 5 Dim y As Double = e.MouseDevice.GetPosition(LayoutRoot).Y - 10 Dim lbl As New Label lbl.Content = "<- X:" & Math.Round(h.XValue, 2) & " - Y:" & Math.Round(h.YValue, 2) lbl.Margin = New Thickness(x, y, 0, 0) LayoutRoot.Children.Insert(0, lbl)
End Sub
Private Sub Bind() Dim ds As New System.Data.DataSet ds.ReadXml("C:\TestXMLBinding\TestXMLBinding\Data\ScatterplotData.xml") Dim axisX As New Infragistics.Windows.Chart.Axis axisX.AxisType = Infragistics.Windows.Chart.AxisType.PrimaryX axisX.Label.Format = "{0:n3}" Name = "X" XamChart1.Axes.Add(axisX) Dim axisY As New Infragistics.Windows.Chart.Axis axisY.AxisType = Infragistics.Windows.Chart.AxisType.PrimaryY axisY.Label.Format = "{0:n1}" Name = "Y" XamChart1.Axes.Add(axisY) Dim s As Infragistics.Windows.Chart.Series = New Infragistics.Windows.Chart.Series s.DataSource = ds.Tables(0) s.DataMapping = "label=x;value=y" s.ChartType = Infragistics.Windows.Chart.ChartType.Bar s.AxisX = "X" s.AxisY = "Y" XamChart1.Series.Add(s) End Sub
although the ordinal axes (X in column chart, Y in bar chart) are displaying "100, 120, etc," these are just labels; they do not represent a numeric value on the axis. they could just as easily say "john, paul, george, and ringo." so the values HitTest is returning are correct. i think what you need to do is round to the nearest integer, then get the point back from your datasource using that value as an index.
if you want the X and Y axes to both represent a numeric scale, try using a Scatter or ScatterLine series.
Hi David,
I am experiencing a similar issue. I have a line chart with dates on x- axis. I want to track the mouse move and display the x-axis date and y-axis value anywhere on the chart. I tried using hittest xvalue and yvalue. But xvalue is returning the point location and not the label. I tried using datapoint.label, but that just returns the labels for a valid data point and not any point on chart.
Please advise.