Skip to main content
All docs
V24.1

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.v24.1.dll

NuGet Package: DevExpress.Charts

Declaration

[Browsable(false)]
public IComparer YArgumentComparer { get; set; }

Property Value

Type Description
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.
Custom sorting Default sorting
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;
        }
    }
}
See Also