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


comparer
An object that implements the IComparer interface and provides the custom sorting logic.
Comparing interface.
series
The Series object to be sorted.
Series to sort.

Performs a custom sort on a series' data points.


Sort series data points in specified order.

Syntax

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

Parameters

comparer
An object that implements the IComparer interface and provides the custom sorting logic.
Comparing interface.
series
The Series object to be sorted.
Series to sort.

Example

Perform a custom sort in ascending order, based on the labels of data points in "Series1".
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(), Chart1.Series("Series1"))
End Sub
...

Public Class CustomComparer Implements IComparer
' compares two data point by their Label. 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 a 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.

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

To perform a custom sort for more than one series per function call use the definition that take a seriesName string parameter.

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.