Back to Devexpress

HeatmapDataSourceAdapter.YArgumentComparer Property

corelibraries-devexpress-dot-xtracharts-dot-heatmap-dot-heatmapdatasourceadapter-70407fe7.md

latest7.7 KB
Original Source

HeatmapDataSourceAdapter.YArgumentComparer Property

Gets or sets a comparer that is used to specify custom sort order for y-arguments.

Namespace : DevExpress.XtraCharts.Heatmap

Assembly : DevExpress.XtraCharts.v25.2.dll

NuGet Package : DevExpress.Charts

Declaration

csharp
[Browsable(false)]
public IComparer YArgumentComparer { get; set; }
vb
<Browsable(False)>
Public Property YArgumentComparer As IComparer

Property Value

TypeDescription
IComparer

An object that implements the IComparer interface.

|

Remarks

The following example sorts heatmap y-arguments:

Custom sort is applied to y-arguments.Y-arguments are shown in default order.
csharp
using DevExpress.XtraCharts.Heatmap;
using System;
using System.Collections;
using System.Collections.Generic;

namespace HeatmapArgumentSorting {
    public partial class Form1 : DevExpress.XtraEditors.XtraForm {
        public Form1() {
            InitializeComponent();

            heatmapControl1.DataAdapter = new HeatmapDataSourceAdapter {
                DataSource = DataPoint.GetDataPoints(),
                XArgumentDataMember = "XArgument",
                YArgumentDataMember = "YArgument",
                ColorDataMember = "Value",
                YArgumentComparer = new NumberComparer(),
            };

            HeatmapRangeColorProvider colorProvider = new HeatmapRangeColorProvider { ApproximateColors = true };
            colorProvider.RangeStops.Add(new HeatmapRangeStop(0, HeatmapRangeStopType.Percentage));
            colorProvider.RangeStops.Add(new HeatmapRangeStop(2));
            colorProvider.RangeStops.Add(new HeatmapRangeStop(4));
            colorProvider.RangeStops.Add(new HeatmapRangeStop(1, HeatmapRangeStopType.Percentage));
            heatmapControl1.ColorProvider = colorProvider;
        }

    }
    class NumberComparer : IComparer {
        public int Compare(object x, object y) {
            int iX = NumberConverter.ToInt(x);
            int iY = NumberConverter.ToInt(y);
            return iX - iY;
        }
    }
    class NumberConverter {
        public static int ToInt(object o) {
            string stringNumber = o as string;
            int number = 0;
            if (stringNumber == null) return -1;
            if (Int32.TryParse(stringNumber, out number))
                return number;
            switch (stringNumber.ToLower()) {
                case "one": return 1;
                case "two": return 2;
                case "three": return 3;
            }
            return number;
        }
    }
    public class DataPoint {
        public string XArgument { get; set; }
        public string YArgument { get; set; }
        public double Value { get; set; }
        public DataPoint(string x, string y, double value) {
            this.XArgument = x;
            this.YArgument = y;
            this.Value = value;
        }
        public static List<DataPoint> GetDataPoints() {
            List<DataPoint> data = new List<DataPoint> {
                new DataPoint("A", "Two", 5.2),
                new DataPoint("A", "Three", 4.27),
                new DataPoint("A", "One", 3.77),
                new DataPoint("B", "Two", 5.2),
                new DataPoint("B", "Three", 4.27),
                new DataPoint("B", "One", 6.77),
                new DataPoint("C", "Two", 4.2),
                new DataPoint("C", "One", 2.27),
                new DataPoint("C", "Three", 7.77),
            };
            return data;
        }
    }
}
vb
Imports DevExpress.XtraCharts.Heatmap
Imports System.Collections
Imports System.Collections.Generic

Namespace HeatmapArgumentSorting
    Public Partial Class Form1
        Inherits DevExpress.XtraEditors.XtraForm

        Public Sub New()
            InitializeComponent()
            heatmapControl1.DataAdapter = New HeatmapDataSourceAdapter With {
                .DataSource = DataPoint.GetDataPoints(),
                .XArgumentDataMember = "XArgument",
                .YArgumentDataMember = "YArgument",
                .ColorDataMember = "Value",
                .YArgumentComparer = New NumberComparer()
            }
            Dim colorProvider As HeatmapRangeColorProvider = New HeatmapRangeColorProvider With {
                .ApproximateColors = True
            }
            colorProvider.RangeStops.Add(New HeatmapRangeStop(0, HeatmapRangeStopType.Percentage))
            colorProvider.RangeStops.Add(New HeatmapRangeStop(2))
            colorProvider.RangeStops.Add(New HeatmapRangeStop(4))
            colorProvider.RangeStops.Add(New HeatmapRangeStop(1, HeatmapRangeStopType.Percentage))
            heatmapControl1.ColorProvider = colorProvider
        End Sub
    End Class

    Friend Class NumberComparer
        Implements IComparer

        Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements IComparer.Compare
            Dim iX As Integer = NumberConverter.ToInt(x)
            Dim iY As Integer = NumberConverter.ToInt(y)
            Return iX - iY
        End Function
    End Class

    Friend Class NumberConverter
        Public Shared Function ToInt(ByVal o As Object) As Integer
            Dim stringNumber As String = TryCast(o, String)
            Dim number As Integer = 0
            If Equals(stringNumber, Nothing) Then Return -1
            If Integer.TryParse(stringNumber, number) Then Return number

            Select Case stringNumber.ToLower()
                Case "one"
                    Return 1
                Case "two"
                    Return 2
                Case "three"
                    Return 3
            End Select

            Return number
        End Function
    End Class

    Public Class DataPoint
        Public Property XArgument As String
        Public Property YArgument As String
        Public Property Value As Double

        Public Sub New(ByVal x As String, ByVal y As String, ByVal value As Double)
            XArgument = x
            YArgument = y
            Me.Value = value
        End Sub

        Public Shared Function GetDataPoints() As List(Of DataPoint)
            Dim data As List(Of DataPoint) = New List(Of DataPoint) From {
                New DataPoint("A", "Two", 5.2),
                New DataPoint("A", "Three", 4.27),
                New DataPoint("A", "One", 3.77),
                New DataPoint("B", "Two", 5.2),
                New DataPoint("B", "Three", 4.27),
                New DataPoint("B", "One", 6.77),
                New DataPoint("C", "Two", 4.2),
                New DataPoint("C", "One", 2.27),
                New DataPoint("C", "Three", 7.77)
            }
            Return data
        End Function
    End Class
End Namespace

See Also

HeatmapDataSourceAdapter Class

HeatmapDataSourceAdapter Members

DevExpress.XtraCharts.Heatmap Namespace