AxisBase.QualitativeScaleComparer Property

Gets or sets the Comparer class object used to compare deferred-axis qualitative scale values.

Namespace: DevExpress.XtraCharts

Assembly: DevExpress.XtraCharts.v20.1.dll

Declaration

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

Property Value

Type Description
IComparer

An object of the class that implements the IComparer interface.

Remarks

How to implement a custom sort order

To implement a custom sort order for qualitative scale values, assign the AxisBase.QualitativeScaleComparer property to an object of a class that implements the IComparer interface.

NOTE

A complete sample project is available in the following repository: https://github.com/DevExpress-Examples/how-to-sort-qualitative-values-in-a-custom-order-t316036.

using System;
using System.Collections;

namespace QualitativeScaleCustomSortOrderSample {
    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;
        }
    }
}
private void OnLoad(object sender, EventArgs e) {
    XYDiagram diagram = chart.Diagram as XYDiagram;
    if (diagram == null) return;
    diagram.AxisX.QualitativeScaleComparer = new NumberComparer();
}

How to sort multiple series with different point arguments

This example shows how to use the CaseInsensitiveComparer class to sort multiple series with different point arguments.

private void Form1_Load(System.Object sender, System.EventArgs e){
  chartNewCusts.SeriesTemplate.ValueScaleType = ScaleType.Numerical;
  chartNewCusts.SeriesTemplate.LegendTextPattern = "{V:n}";
  chartNewCusts.SeriesTemplate.CrosshairLabelPattern = "{S} : {V}";
  chartNewCusts.SeriesTemplate.Label.EnableAntialiasing = DevExpress.Utils.DefaultBoolean.True;
  chartNewCusts.SeriesTemplate.Label.Shadow.Visible = false;
  chartNewCusts.SeriesTemplate.Label.TextColor = Color.Black;
  chartNewCusts.SeriesTemplate.Label.ResolveOverlappingMode = ResolveOverlappingMode.HideOverlapped;
  chartNewCusts.SeriesTemplate.LabelsVisibility = DevExpress.Utils.DefaultBoolean.True;
  chartNewCusts.SeriesTemplate.Label.TextPattern = "{V:n0}";
  chartNewCusts.DataSource = GetSales();
  chartNewCusts.SeriesSorting = SortingMode.Ascending;
  chartNewCusts.SeriesDataMember = "GroupField";
  chartNewCusts.SeriesTemplate.ArgumentDataMember = "MonthYear";
  chartNewCusts.SeriesTemplate.ValueDataMembers.AddRange(new string[] { "NewCustCount" });
  XYDiagram diagram = chartNewCusts.Diagram as XYDiagram;
  if (diagram == null)
      return;
  diagram.AxisX.QualitativeScaleComparer = new CaseInsensitiveComparer();
  try{
    (XYDiagram)chartNewCusts.Diagram.AxisY.Label.TextPattern = "{V:n0}";
    (XYDiagram)chartNewCusts.Diagram.AxisY.Label.EnableAntialiasing = DevExpress.Utils.DefaultBoolean.True;
    (XYDiagram)chartNewCusts.Diagram.AxisX.Label.EnableAntialiasing = DevExpress.Utils.DefaultBoolean.True;
  }
  catch (Exception ex){
  }
}

private DataTable GetSales(){
  DataTable table = new DataTable("Sample");

  table.Columns.Add("MonthYear", typeof(string));
  table.Columns.Add("GroupField", typeof(string));
  table.Columns.Add("NewCustCount", typeof(int));

  DataRow row;

  row = table.NewRow();
  row("MonthYear") = "01-2015";
  row("GroupField") = "Customer Referral";
  row("NewCustCount") = 1;
  table.Rows.Add(row);

  row = table.NewRow();
  row("MonthYear") = "01-2015";
  row("GroupField") = "Walk-In";
  row("NewCustCount") = 1;
  table.Rows.Add(row);

  //...

  return table;
}

Result:

Implements

DevExpress.Charts.Native.IAxisData.QualitativeScaleComparer
See Also