corelibraries-devexpress-dot-xtracharts-dot-seriesbase-81b00f96.md
Gets or sets the data source field name that contains series point colors.
Namespace : DevExpress.XtraCharts
Assembly : DevExpress.XtraCharts.v25.2.dll
NuGet Package : DevExpress.Charts
[XtraChartsLocalizableCategory(XtraChartsCategory.Data)]
public string ColorDataMember { get; set; }
<XtraChartsLocalizableCategory(XtraChartsCategory.Data)>
Public Property ColorDataMember As String
| Type | Description |
|---|---|
| String |
The data source field name that contains series point colors.
|
Series Point Colorizers define colors based on values that the ColorDataMember contains. A colorizer determines how to process the ColorDataMember values:
ColorDataMember values used as key values.When the Chart Control aggregates series data, the aggregated point has the color that mostly occurs within the aggregated interval.
To configure and use the Key-Color colorizer, perform the following steps.
Create a KeyColorColorizer object and assign it to the SeriesViewBase.Colorizer property.
Populate the KeyColorColorizer.Keys collection.
Specify the ChartPaletteColorizerBase.Palette property if you want to use a non-default palette to colorize your data.
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
}
}
Imports System
Imports System.Collections.Generic
Imports System.Windows.Forms
Imports System.Xml.Linq
Imports DevExpress.XtraCharts
Namespace KeyColorColorizerExample
Partial Public Class Form1
Inherits Form
Private Const filepath As String = "..//..//Data//GDP.xml"
Public Sub New()
InitializeComponent()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
' #Region "#BarSeries"
' Create and customize a bar series.
Dim barSeries As New Series() With {
.DataSource = LoadData(filepath),
.ArgumentDataMember = "Country",
.ColorDataMember = "Region",
.View = New SideBySideBarSeriesView()
}
barSeries.View.Colorizer = CreateColorizer()
barSeries.ValueDataMembers.AddRange(New String() { "Product" })
' #End Region ' #BarSeries
' Add the series to the ChartControl's Series collection.
chartControl1.Series.Add(barSeries)
' Show a title for the values axis.
CType(chartControl1.Diagram, XYDiagram).AxisY.Title.Text = "GDP per capita, $"
CType(chartControl1.Diagram, XYDiagram).AxisY.Title.Visibility = DevExpress.Utils.DefaultBoolean.True
End Sub
#Region "#KeyColorColorier"
' Creates the Key-Color colorizer for the bar chart.
Private Function CreateColorizer() As ChartColorizerBase
Dim colorizer As New KeyColorColorizer() With {.PaletteName = "Apex"}
colorizer.Keys.Add("Africa")
colorizer.Keys.Add("America")
colorizer.Keys.Add("Asia")
colorizer.Keys.Add("Australia")
colorizer.Keys.Add("Europe")
Return colorizer
End Function
#End Region ' #KeyColorColorier
#Region "#DataLoad"
Private Class HpiPoint
Public Property Country() As String
Public Property Product() As Double
Public Property Region() As String
End Class
' Loads data from an XML data source.
Private Shared Function LoadData(ByVal filepath As String) As List(Of HpiPoint)
Dim doc As XDocument = XDocument.Load(filepath)
Dim points As New List(Of HpiPoint)()
For Each element As XElement In doc.Element("G20HPIs").Elements("CountryStatistics")
points.Add(New HpiPoint() With {
.Country = element.Element("Country").Value,
.Product = Convert.ToDouble(element.Element("Product").Value),
.Region = element.Element("Region").Value
})
Next element
Return points
End Function
#End Region ' #DataLoad
End Class
End Namespace
<?xml version="1.0" encoding="utf-8" ?>
<G20HPIs>
<CountryStatistics>
<Country>Argentina</Country>
<Region>America</Region>
<Product>16011.6728032264</Product>
</CountryStatistics>
<CountryStatistics>
<Country>Australia</Country>
<Region>Australia</Region>
<Product>38159.6336533223</Product>
</CountryStatistics>
<CountryStatistics>
<Country>Brazil</Country>
<Region>America</Region>
<Product>11210.3908053823</Product>
</CountryStatistics>
<CountryStatistics>
<Country>Canada</Country>
<Region>America</Region>
<Product>39050.1673163719</Product>
</CountryStatistics>
<CountryStatistics>
<Country>China</Country>
<Region>Asia</Region>
<Product>7599</Product>
</CountryStatistics>
<CountryStatistics>
<Country>France</Country>
<Region>Europe</Region>
<Product>34123.1966249035</Product>
</CountryStatistics>
<CountryStatistics>
<Country>Germany</Country>
<Region>Europe</Region>
<Product>37402.2677660974</Product>
</CountryStatistics>
<CountryStatistics>
<Country>India</Country>
<Region>Asia</Region>
<Product>3425.4489267524</Product>
</CountryStatistics>
<CountryStatistics>
<Country>Indonesia</Country>
<Region>Asia</Region>
<Product>4325.2533282173</Product>
</CountryStatistics>
<CountryStatistics>
<Country>Italy</Country>
<Region>Europe</Region>
<Product>31954.1751781228</Product>
</CountryStatistics>
<CountryStatistics>
<Country>Japan</Country>
<Region>Asia</Region>
<Product>33732.8682226596</Product>
</CountryStatistics>
<CountryStatistics>
<Country>Mexico</Country>
<Region>America</Region>
<Product>14563.884253986</Product>
</CountryStatistics>
<CountryStatistics>
<Country>Russia</Country>
<Region>Europe</Region>
<Product>19891.3528339013</Product>
</CountryStatistics>
<CountryStatistics>
<Country>Saudi Arabia</Country>
<Region>Asia</Region>
<Product>22713.4852913284</Product>
</CountryStatistics>
<CountryStatistics>
<Country>South Africa</Country>
<Region>Africa</Region>
<Product>10565.1840563081</Product>
</CountryStatistics>
<CountryStatistics>
<Country>South Korea</Country>
<Region>Asia</Region>
<Product>29101.0711400706</Product>
</CountryStatistics>
<CountryStatistics>
<Country>Turkey</Country>
<Region>Africa</Region>
<Product>15686.860167575</Product>
</CountryStatistics>
<CountryStatistics>
<Country>United Kingdom</Country>
<Region>Europe</Region>
<Product>35686.1997705521</Product>
</CountryStatistics>
<CountryStatistics>
<Country>Spain</Country>
<Region>Europe</Region>
<Product>32230.3585974199</Product>
</CountryStatistics>
<CountryStatistics>
<Country>USA</Country>
<Region>America</Region>
<Product>47153.0094273427</Product>
</CountryStatistics>
</G20HPIs>
<?xml version="1.0" encoding="utf-8" ?>
<G20HPIs>
<CountryStatistics>
<Country>Argentina</Country>
<Region>America</Region>
<Product>16011.6728032264</Product>
</CountryStatistics>
<CountryStatistics>
<Country>Australia</Country>
<Region>Australia</Region>
<Product>38159.6336533223</Product>
</CountryStatistics>
<CountryStatistics>
<Country>Brazil</Country>
<Region>America</Region>
<Product>11210.3908053823</Product>
</CountryStatistics>
<CountryStatistics>
<Country>Canada</Country>
<Region>America</Region>
<Product>39050.1673163719</Product>
</CountryStatistics>
<CountryStatistics>
<Country>China</Country>
<Region>Asia</Region>
<Product>7599</Product>
</CountryStatistics>
<CountryStatistics>
<Country>France</Country>
<Region>Europe</Region>
<Product>34123.1966249035</Product>
</CountryStatistics>
<CountryStatistics>
<Country>Germany</Country>
<Region>Europe</Region>
<Product>37402.2677660974</Product>
</CountryStatistics>
<CountryStatistics>
<Country>India</Country>
<Region>Asia</Region>
<Product>3425.4489267524</Product>
</CountryStatistics>
<CountryStatistics>
<Country>Indonesia</Country>
<Region>Asia</Region>
<Product>4325.2533282173</Product>
</CountryStatistics>
<CountryStatistics>
<Country>Italy</Country>
<Region>Europe</Region>
<Product>31954.1751781228</Product>
</CountryStatistics>
<CountryStatistics>
<Country>Japan</Country>
<Region>Asia</Region>
<Product>33732.8682226596</Product>
</CountryStatistics>
<CountryStatistics>
<Country>Mexico</Country>
<Region>America</Region>
<Product>14563.884253986</Product>
</CountryStatistics>
<CountryStatistics>
<Country>Russia</Country>
<Region>Europe</Region>
<Product>19891.3528339013</Product>
</CountryStatistics>
<CountryStatistics>
<Country>Saudi Arabia</Country>
<Region>Asia</Region>
<Product>22713.4852913284</Product>
</CountryStatistics>
<CountryStatistics>
<Country>South Africa</Country>
<Region>Africa</Region>
<Product>10565.1840563081</Product>
</CountryStatistics>
<CountryStatistics>
<Country>South Korea</Country>
<Region>Asia</Region>
<Product>29101.0711400706</Product>
</CountryStatistics>
<CountryStatistics>
<Country>Turkey</Country>
<Region>Africa</Region>
<Product>15686.860167575</Product>
</CountryStatistics>
<CountryStatistics>
<Country>United Kingdom</Country>
<Region>Europe</Region>
<Product>35686.1997705521</Product>
</CountryStatistics>
<CountryStatistics>
<Country>Spain</Country>
<Region>Europe</Region>
<Product>32230.3585974199</Product>
</CountryStatistics>
<CountryStatistics>
<Country>USA</Country>
<Region>America</Region>
<Product>47153.0094273427</Product>
</CountryStatistics>
</G20HPIs>
The following code snippets (auto-collected from DevExpress Examples) contain references 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.
winforms-dashboard-custom-items/CS/TutorialsCustomItems/CustomItems/FunnelItemControlProvider.cs#L59
series.ArgumentDataMember = dashboardItem.Metadata.Arguments.Last().UniqueId;
series.ColorDataMember = flatData.GetColoringColumn(dashboardItem.Metadata.Value.UniqueId).Name;
}
series.ArgumentDataMember = arguments.Last().UniqueId;
series.ColorDataMember = flatData.GetColoringColumn(values[0].UniqueId).Name;
}
series.ArgumentDataMember = dashboardItem.Metadata.Arguments.Last().UniqueId;
series.ColorDataMember = flatData.GetColoringColumn(dashboardItem.Metadata.Value.UniqueId).Name;
}
winforms-charts-change-series-line-color-when-value-is-under-predefined-level/CS/Form1.cs#L29
series.BindToData(PointGenerator.Generate(), "X", "Y");
series.ColorDataMember = "Y";
chartControl1.Series.Add(series);
winforms-dashboard-custom-items/VB/TutorialsCustomItems/CustomItems/FunnelItemControlProvider.vb#L60
End If
series.ColorDataMember = flatData.GetColoringColumn(dashboardItem.Metadata.Value.UniqueId).Name
End If
End If
series.ColorDataMember = flatData.GetColoringColumn(values(0).UniqueId).Name
End If
End If
series.ColorDataMember = flatData.GetColoringColumn(dashboardItem.Metadata.Value.UniqueId).Name
End If
winforms-charts-change-series-line-color-when-value-is-under-predefined-level/VB/Form1.vb#L33
series.BindToData(PointGenerator.Generate(), "X", "Y")
series.ColorDataMember = "Y"
chartControl1.Series.Add(series)
See Also