0

I have a DevExpress XtraChart object with several series, all of type: line.

I have a requirement from a client to align the series by the max value of each series. This is without regard to the attached axis, has anyone done this before?

1 Answers1

0

Although I was interested in displaying this on the chart element, the 'work' was done on the underlying DataSet.

I was able to achieve this by looping through the series collection, deriving the max value of the first series, through a SQL query, and then each subsequent series, and noting the difference, and then adding or subtracting the difference at the DataSet level.

Here's the code:

Private Sub cbAlignPeaks_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbAlignPeaks.CheckedChanged
    Dim dt As DataTable = chart.DataSource
    Dim Row() As Data.DataRow
    Dim s As Series = Nothing
    Dim dtr As DataTableReader = Nothing
    Dim maxTimeGet, maxTimeSet, diff As Decimal

    Me.Cursor = Cursors.WaitCursor
    If cbAlignPeaksPre.Checked Then
        For i As Integer = 0 To chartPreTim.Series.Count - 1
            s = chartPreTim.Series(i)
            If _offsets.Count = chartPreTim.Series.Count - 1 Then
                If i > 0 Then
                    diff = _offsets(s.DataFilters(0).Value)
                    Row = dt.Select("BORING_NAME = '" & s.Name & "'")
                    For k As Integer = 0 To Row.Count - 1
                        Row(k)("TIME_SEC") = Row(k)("TIME_SEC") + diff
                    Next
                End If
            Else
                If i = 0 Then 'get adjustment info
                    dtr = getDetectorMax(s.DataFilters(0).Value, cbDetectors.Text, timType.PRE) ' <-- getDetectorMax runs a SQL query returning the max value
                    If dtr.Read Then
                        maxTimeGet = dtr("TIME_SEC")
                    End If
                Else 'set adjustment info
                    dtr = Nothing
                    dtr = getDetectorMax(s.DataFilters(0).Value, cbDetectors.Text, timType.PRE)
                    If dtr.Read Then
                        maxTimeSet = dtr("TIME_SEC")
                    End If

                    If maxTimeGet > maxTimeSet Then
                        diff = maxTimeGet - maxTimeSet
                        _offsets.Add(s.DataFilters(0).Value, diff)
                        Row = dt.Select("BORING_NAME = '" & s.DataFilters(0).Value & "'")
                        For k As Integer = 0 To Row.Count - 1
                            Row(k)("TIME_SEC") = Row(k)("TIME_SEC") + diff
                        Next
                    Else
                        diff = maxTimeSet - maxTimeGet
                        _offsets.Add(s.DataFilters(0).Value, diff * -1)
                        Row = dt.Select("BORING_NAME = '" & s.DataFilters(0).Value & "'")
                        For k As Integer = 0 To Row.Count - 1
                            Row(k)("TIME_SEC") = Row(k)("TIME_SEC") - diff
                        Next
                    End If
                End If
            End If
        Next
    Else
        For i As Integer = 1 To chartPreTim.Series.Count - 1 ' We skip item 0 as that's the baseline
            s = chartPreTim.Series(i)
            diff = _offsets(s.DataFilters(0).Value)
            Row = dt.Select("BORING_NAME = '" & s.DataFilters(0).Value & "'")
            For k As Integer = 0 To Row.Count - 1
                Row(k)("TIME_SEC") = Row(k)("TIME_SEC") - diff
            Next
        Next
    End If
    chartPreTim.RefreshData()
    chartPreTim.Refresh()
    Me.Cursor = Cursors.Default
End Sub