Dundas Chart for Windows Forms
Sort(IComparer,String) Method
See Also  Example Send comments on this topic.
DundasWinChart Assembly > Dundas.Charting.WinControl Namespace > DataManipulator Class > Sort Method : Sort(IComparer,String) Method


comparer
An object that implements the IComparer interface and provides the custom sorting logic.
Comparing interface.
seriesName
The name(s) of the series to sort. For multiple series use a comma-separated list.
Comma separated series names to sort.

Performs a custom sort on one or more series.


Sort series data points in specified order.

Syntax

Visual Basic (Declaration)  
Public Overloads Sub Sort( _
   ByVal comparer As IComparer, _
   ByVal seriesName As String _
) 
Visual Basic (Usage) Copy Code
Dim instance As DataManipulator
Dim comparer As IComparer
Dim seriesName As String
 
instance.Sort(comparer, seriesName)
C#  
public void Sort( 
   IComparer comparer,
   string seriesName
)

Parameters

comparer
An object that implements the IComparer interface and provides the custom sorting logic.
Comparing interface.
seriesName
The name(s) of the series to sort. For multiple series use a comma-separated list.
Comma separated series names to sort.

Example

Perform a custom sort on two data series in ascending order, based on the labels of data points. Note that the value returned by the overridden Compare method determines how points are sorted within a series.
Visual Basic Copy Code
Imports Dundas.Charting.WinControl
...

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Chart1.DataManipulator.Sort(New CustomComparer(), "Series1,Series2")
End Sub
...

Public Class CustomComparer Implements IComparer
' compares two data point by their Label and returns a value indicating
' whether one is less than, equal to or greater than the other

    Public Function Compare(ByVal a As Object, ByVal b As Object) As Integer Implements IComparer.Compare

        Dim pointA As DataPoint = a
        Dim pointB As DataPoint = b

        ' compares data points Label property
        If pointA.Label < pointB.Label Then
            Compare = -1
        ElseIf pointA.Label > pointB.Label Then
            Compare = 1
        Else
            Compare = 0
        End If

    End Function

End Class

Remarks

This method performs a custom sort on the specified series' data points, and the sort logic is defined by the comparer parameter. Override and implement the Compare method of the IComparer interface, perform the comparison(s) and then return True or False. The sort order is determined by the return value.

Note that if multiple series are sorted then the series must be aligned, otherwise an exception will be thrown. Refer to the Aligning Series topic for information on aligned series.

The two object parameters of the Compare method must always be of type DataPoint.

IMPORTANT: ALL data points, regardless of the series they belong to, are sorted based on the first series (i.e. if the position of a data point in the first series changes, all corresponding points in the other series changes as well) .

Requirements

Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family

See Also

© 2009 All Rights Reserved.