Skip to main content
A newer version of this page is available. .

SeriesBase.ColorDataMember Property

Gets or sets the name of the data member name that is used to specify series point colors.

Namespace: DevExpress.XtraCharts

Assembly: DevExpress.XtraCharts.v19.2.dll

Declaration

[XtraChartsLocalizableCategory(XtraChartsCategory.Data)]
public string ColorDataMember { get; set; }

Property Value

Type Description
String

A String value that specifies the data member’s name.

Remarks

The Chart Control’s point colorizers define point colors based on values that the color data member provides. A colorizer determines how to process the color data member’s values:

  • ColorObjectColorizer provides the color data member’s values to the SeriesPoint.Color property if these values have the Color type or a type that can be converted to a color (integer number or string). This is the default chart colorizer.
  • KeyColorColorizer uses the color data member’s values as key values. Point colors depend on keys’ values.
  • RangeColorizer allows you to specify color ranges based on the color data member’s values. These values should be floating point numbers. You can use IColorizerValueProvider to convert the data member’s values to floating point values.

When the Chart Control aggregates series data, the aggregated point has the color that mostly occurs on the aggregated interval.

Example

To configure and use the Key-Color colorizer, perform the following steps.

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Xml.Linq;
using DevExpress.XtraCharts;

namespace KeyColorColorizerExample {
    public partial class Form1 : Form {
        const string filepath = "..//..//Data//GDP.xml";

        public Form1() {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e) {
            #region #BarSeries
            // Create and customize a bar series.
            Series barSeries = new Series() {
                DataSource = LoadData(filepath),
                ArgumentDataMember = "Country",
                ColorDataMember = "Region",
                View = new SideBySideBarSeriesView()
            };
            barSeries.View.Colorizer = CreateColorizer();
            barSeries.ValueDataMembers.AddRange(new string[] { "Product" });
            #endregion #BarSeries

            // Add the series to the ChartControl's Series collection.
            chartControl1.Series.Add(barSeries);

            // Show a title for the values axis.
            ((XYDiagram)chartControl1.Diagram).AxisY.Title.Text = "GDP per capita, $";
            ((XYDiagram)chartControl1.Diagram).AxisY.Title.Visibility = DevExpress.Utils.DefaultBoolean.True;
        }

        #region #KeyColorColorier
        // Creates the Key-Color colorizer for the bar chart.
        ChartColorizerBase CreateColorizer() {
            KeyColorColorizer colorizer = new KeyColorColorizer() {
                PaletteName = "Apex"
            };
            colorizer.Keys.Add("Africa");
            colorizer.Keys.Add("America");
            colorizer.Keys.Add("Asia");
            colorizer.Keys.Add("Australia");
            colorizer.Keys.Add("Europe");

            return colorizer;
        }
        #endregion #KeyColorColorier

        #region #DataLoad
        class HpiPoint {
            public string Country { get; set; }
            public double Product { get; set; }
            public string Region { get; set; }
        }

        // Loads data from an XML data source.
        static List<HpiPoint> LoadData(string filepath) {
            XDocument doc = XDocument.Load(filepath);
            List<HpiPoint> points = new List<HpiPoint>();
            foreach (XElement element in doc.Element("G20HPIs").Elements("CountryStatistics")) {
                points.Add(new HpiPoint() {
                    Country = element.Element("Country").Value,
                    Product = Convert.ToDouble(element.Element("Product").Value),
                    Region = element.Element("Region").Value
                });
            }
            return points;
        }
        #endregion #DataLoad
    }
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the ColorDataMember 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