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
235
Binding datatable to NumericXAxis
posted

Hi.  I'm in the process of converting WPF XamCharts to XamDataCharts.  I'm tried to find an example of binding a datatable to ScatterLineSeries - I Found an example using a CatergoryXAxis but I'm unable to get more than the minimum Y Axis label to show up and none of the X Axis labels.  The graph itself is working great, I just don't have labels.  I have tried letting letting it autorange and have tried various setting for labels and MemberPath, but nothing seems to produce labels.   Here is the code I have:

                                     <ig:XamDataChart x:Name="TrainingStatGraph"

                                                     Grid.ColumnSpan="2"

                                                     Margin="2,2,-2,-2"

                                                     Grid.RowSpan="2" >

                                        <ig:XamDataChart.BindingGroup>

                                            <BindingGroup/>

                                        </ig:XamDataChart.BindingGroup>

                                        <ig:XamDataChart.Axes>

                                            <ig:NumericXAxis

                                                x:Name="xmXAxis"

                                                DataContext="{Binding}"

                                                Label="{}{Label}}">

                                                <ig:NumericXAxis.LabelSettings >

                                                    <ig:AxisLabelSettings Location="OutsideBottom" Extent="35" />

                                                </ig:NumericXAxis.LabelSettings>

                                            </ig:NumericXAxis>

                                            <ig:NumericYAxis x:Name="xmYAxis">

                                                <ig:NumericYAxis.LabelSettings>

                                                    <ig:AxisLabelSettings Extent="50" />   

                                                </ig:NumericYAxis.LabelSettings>                                                    

                                            </ig:NumericYAxis>

                                        </ig:XamDataChart.Axes>

                                        <ig:XamDataChart.Series>

                                            <ig:ScatterLineSeries 

                                                       ItemsSource="{Binding}"

                                                MarkerType="None"

                                                XMemberPath="xVal"

                                                YMemberPath="yVal"

                                                       XAxis="{Binding ElementName=xmXAxis}"

                                                       YAxis="{Binding ElementName=xmYAxis}"/>

                                        </ig:XamDataChart.Series>

                                    </ig:XamDataChart>

 

    Public Sub BuildGraph(ByRef DataChart As XamDataChart, ByRef xmXAxis As Infragistics.Controls.Charts.NumericXAxis, ByRef xmYAxis As Infragistics.Controls.Charts.NumericYAxis)

        Dim CurCulture As String

        CurCulture = System.Threading.Thread.CurrentThread.CurrentCulture.ToString

 

        Try

            If (mConn.State = ConnectionState.Closed) Then

                mConn.Open()

            End If

 

            Dim customCulture As New CultureInfo("en-US")

            System.Threading.Thread.CurrentThread.CurrentCulture = customCulture

 

            Dim adapter As New OleDbDataAdapter("SELECT Pass,MAPE FROM MAPE where Prof_code=" & mCurrentProfileCode, mConn)

            Dim ds As New DataSet()

 

            adapter.Fill(ds, "MAPE")

            Dim data = From row In ds.Tables("MAPE").Rows.OfType(Of DataRow)() Select New DataItem() With {.xVal = CDbl(row("Pass")), .yVal = CDbl(row("MAPE"))}

             DataChart.DataContext = data

 

            ' there is only one table here so we can use the number of rows in the dataset as the number of passes

            mPasses = ds.Tables(0).Rows.Count

            If (mPasses = 0) Then

                Exit Sub

            End If

 

            mFinalMAPE = ds.Tables(0).Rows(ds.Tables(0).Rows.Count - 1)("MAPE")

 

            mBestMAPE = ds.Tables(0).Compute("MIN(MAPE)", "")

            mMaxMAPE = ds.Tables(0).Compute("MAX(MAPE)", "")

 

            With xmXAxis

                .DataContext = data 'ds.Tables(0)

                .Interval = FormatNumber((mMaxMAPE - mBestMAPE) / 4, 2)

                '.Label = "xVal"

                .MinimumValue = 0

                .Interval = 5

                .MaximumValue = mPasses

 

            End With

            With xmYAxis.LabelSettings

                .Location = AxisLabelsLocation.OutsideBottom

                .Extent = 25

                .VerticalAlignment = VerticalAlignment.Bottom 

            End With

 

            With xmYAxis

                .MinimumValue = FormatNumber(mBestMAPE - (mBestMAPE * 0.1), 2)

                .MaximumValue = FormatNumber(mMaxMAPE + (mMaxMAPE * 0.1), 2)

                .Interval = FormatNumber((mMaxMAPE - mBestMAPE) / 4, 2)

                If .Interval = 0 Then .Interval = 0.1

                '.Label = "yVal"

                '.LabelSettings.Location = AxisLabelsLocation.OutsideLeft

                .LabelSettings.Extent = 50

            End With

 

            mBestPass = ds.Tables(0).Select("MAPE=" & mBestMAPE.ToString)(0)("Pass")

 

            Dim series As New ScatterLineSeries()

            series.XAxis = xmXAxis

            series.YAxis = xmYAxis

            series.MarkerType = Charts.MarkerType.None

            series.ItemsSource = data 'ds.Tables(0)

            series.XMemberPath = "xVal"

            series.YMemberPath = "yVal"

 

            If DataChart.Series.Count >= 1 Then DataChart.Series.Remove(DataChart.Series(0))

            DataChart.Series.Add(series)

            mConn.Close()

        Catch ex As Exception

            LogHelper.LogError(Me.GetType(), "; " & ex.Message, ex)

        Finally

            Dim retCulture As New CultureInfo(CurCulture)

            System.Threading.Thread.CurrentThread.CurrentCulture = retCulture

        End Try

    End Sub

Public Class DataItem

    Public Property xVal() As Double

        Get

            Return m_xAxis

        End Get

        Set(value As Double)

            m_xAxis = value

        End Set

    End Property

    Private m_xAxis As Double

    Public Property yVal() As Double

        Get

            Return m_YAxis

        End Get

        Set(value As Double)

            m_YAxis = value

        End Set

    End Property

    Private m_YAxis As Double

End Class

 

 Thanks in advance for you help!

Parents Reply Children
No Data