Skip to main content

AxisBase.QualitativeScaleComparer Property

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

Namespace: DevExpress.XtraCharts

Assembly: DevExpress.XtraCharts.v24.1.dll

NuGet Package: DevExpress.Charts

Declaration

[Browsable(false)]
[XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
public IComparer QualitativeScaleComparer { get; set; }

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.

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:

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the QualitativeScaleComparer property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also