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.
David Negley"] 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
I already know this and it works fine on column charts, please have a look at my bar chart (on the right) and give me and exampleof how you would translate any of the X or Y values to an index.
<SERIES> <VALUE X="100" Y="0.1"/> <VALUE X="120" Y="0.2"/> <VALUE X="140" Y="0.3"/> <VALUE X="160" Y="0.4"/> <VALUE X="180" Y="0.5"/> <VALUE X="200" Y="0.6"/> <VALUE X="220" Y="0.7"/> </SERIES>
sorry, i see now why my last response wasn't too helpful. after some investigation i found that this is a bug in the control. i entered as bug # BR34349. it will be resolved in a future hotfix.
the problem is, the bar chart is configured backwards -- that is, the X axis is using ordinal calculations and so internally it seems to range from 0 to numberOfDataPoints + 1. the Y axis ranges from 0 to maximumDataValue, but the maximum might be rounded up.
hi...is it possible to break the y axis as we do in excel so that I can display both small and high values clearly??
sorry, we don't have this feature right now. you can submit a feature request here: http://devcenter.infragistics.com/protected/requestfeature.aspx
my recommendation to handle this problem using the current version is to create a composite chart with 2 line layers and 2 y-axes.