Skip to main content
All docs
V23.2

HeatmapDataSourceAdapter.XArgumentComparer Property

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

Namespace: DevExpress.XtraCharts.Heatmap

Assembly: DevExpress.XtraCharts.v23.2.dll

NuGet Package: DevExpress.Charts

Declaration

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

Property Value

Type Description
IComparer

An object that implements the IComparer interface.

Remarks

The following example sorts heatmap x-arguments:

Custom sort is applied to x-arguments. X-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",
                XArgumentComparer = 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("Two",   "A", 5.2),
                new DataPoint("Three", "A", 4.27),
                new DataPoint("One",   "A", 3.77),
                new DataPoint("Two",   "B", 5.2),
                new DataPoint("Three", "B", 4.27),
                new DataPoint("One",   "B", 6.77),
                new DataPoint("Two",   "C", 4.2),
                new DataPoint("One",   "C", 2.27),
                new DataPoint("Three", "C", 7.77),
            };
            return data;
        }
    }
}
See Also