RangeColorizer Class
A colorizer that allows providing colors based on which range the SeriesBase.ColorDataMember value belongs.
Namespace: DevExpress.XtraCharts
Assembly: DevExpress.XtraCharts.v20.1.dll
NuGet Packages: DevExpress.Charts, DevExpress.WindowsDesktop.Charts
Declaration
Remarks
This class introduces the RangeColorizer.RangeStops property that allows specifying range stops used to determine to which range value belongs, and the RangeColorizer.ValueProvider property, that allows specifying the value provider. This allows you to specify how to provide numeric values based on SeriesBase.ColorDataMember values.
Use the SeriesViewBase.Colorizer property to assign the colorizer to a series view.
For more information about colorizers, refer to the Series Point Colorizer topic.
Example
To use the Range Colorizer, perform the following steps:
Create a
RangeColorizer
object and assign it to the SeriesViewBase.Colorizer property.Populate the RangeColorizer.RangeStops collection.
Specify the ChartPaletteColorizerBase.Palette property if you want to use a non-default palette to colorize the chart.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-colorize-charts-using-the-range-colorizer-t232519
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Xml.Linq;
using DevExpress.XtraCharts;
namespace RangeColorizerExample {
public partial class Form1 : Form {
const string filepath = @"..//..//Data//HPI.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 = "Hpi",
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 #RangeColorizer
// Creates a range colorizer.
ChartColorizerBase CreateColorizer() {
Palette palette = new Palette("Custom");
palette.Add(Color.FromArgb(255, 255, 90, 25), Color.FromArgb(255, 255, 90, 25));
palette.Add(Color.FromArgb(255, 229, 227, 53), Color.FromArgb(255, 229, 227, 53));
palette.Add(Color.FromArgb(255, 110, 201, 92), Color.FromArgb(255, 110, 201, 92));
RangeColorizer colorizer = new RangeColorizer() {
LegendItemPattern = "{V1} - {V2} HPI",
Palette = palette
};
colorizer.RangeStops.AddRange(new double[] { 22, 30, 38, 46, 54, 64 });
return colorizer;
}
#endregion #RangeColorizer
#region #DataLoad
class HpiPoint {
public string Country { get; set; }
public double Product { get; set; }
public double Hpi { 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),
Hpi = Convert.ToDouble(element.Element("HPI").Value),
});
}
return points;
}
#endregion #DataLoad
}
}