Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

KeyColorColorizer Class

A Colorizer that allows choosing the color depending on the Series.ColorDataMember values used as key values.

Namespace: DevExpress.Xpf.Charts

Assembly: DevExpress.Xpf.Charts.v24.2.dll

NuGet Package: DevExpress.Wpf.Charts

#Declaration

public class KeyColorColorizer :
    LegendSupportColorizerBase

#Remarks

This class introduces the KeyColorColorizer.Keys property that allows specifying keys associated with colors, and the KeyColorColorizer.KeyProvider property, that allows specifying how to obtain the key for Series.ColorDataMember values.

For more information about colorizers, refer to the Colorizers topic.

#Example

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

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts" 
        x:Class="KeyColorColorizer.MainWindow"
        Title="MainWindow" Height="720" Width="1280">
    <Window.Resources>
        <XmlDataProvider x:Key="dataProvider" Source="Data/GDP.xml"/>
    </Window.Resources>

    <Grid DataContext="{Binding Source={StaticResource dataProvider}}">
        <dxc:ChartControl>
            <dxc:ChartControl.Titles>
                <dxc:Title Content="GDP for G20" HorizontalAlignment="Center"/>
            </dxc:ChartControl.Titles>
            <dxc:ChartControl.Legend>
                <dxc:Legend/>
            </dxc:ChartControl.Legend>
            <dxc:XYDiagram2D>
                <dxc:BarSideBySideSeries2D DisplayName="GDP" 
                                           DataSource="{Binding XPath=/G20HPIs/CountryStatistics}"
                                           ArgumentDataMember="Country" ValueDataMember="Product"
                                           ColorDataMember="Region">
                    <dxc:BarSideBySideSeries2D.Colorizer>
                        <dxc:KeyColorColorizer>
                            <dxc:KeyColorColorizer.Keys>
                                <sys:String>Africa</sys:String>
                                <sys:String>America</sys:String>
                                <sys:String>Asia</sys:String>
                                <sys:String>Australia</sys:String>
                                <sys:String>Europe</sys:String>
                            </dxc:KeyColorColorizer.Keys>
                            <dxc:KeyColorColorizer.Palette>
                                <dxc:Office2013Palette/>
                            </dxc:KeyColorColorizer.Palette>
                        </dxc:KeyColorColorizer>
                    </dxc:BarSideBySideSeries2D.Colorizer>
                </dxc:BarSideBySideSeries2D>
            </dxc:XYDiagram2D>
        </dxc:ChartControl>
    </Grid>
</Window>
See Also