Skip to main content

ColorScheme Class

A color scheme used to color dashboard item elements.

Namespace: DevExpress.DashboardCommon

Assembly: DevExpress.Dashboard.v26.1.Core.dll

Declaration

public class ColorScheme :
    NotifyingCollection<ColorSchemeEntry>

Remarks

You can color dashboard item elements in two ways:

Global Color Scheme
Provides consistent colors for identical values across the dashboard. To access the dashboard color scheme, use the Dashboard.ColorScheme property.
Local Color Scheme
Provides an independent set of colors for each dashboard item. The Chart and Pie items expose the ColorScheme property to access it.

Dashboard items that support color variation expose the ColoringOptions property. This property returns a DashboardItemColoringOptions object. Set its DashboardItemColoringOptions.UseGlobalColors property to choose between a global and local color scheme.

You can apply specific colors to dimension values/measures or their combinations.

Specify the color mode with the following properties:

The ColorScheme class is a collection of ColorSchemeEntry objects that map dimension values/measures to colors and styles. Use the following members:

Tip

Documentation:
Coloring

Example

The following example demonstrates how to customize a dashboard color scheme to color specified dimension values using predefined colors.

In this example, the dashboard contains Pie and Chart dashboard items, whose dimension values are colored by hue. Dimension values and corresponding colors are stored in a data table.

To add custom colors to the dashboard color scheme (the Dashboard.ColorScheme property), create the ColorSchemeEntry objects.

The ColorSchemeEntry class has the following properties:

View Example: How to Customize a Dashboard Color Scheme

using DevExpress.DashboardCommon;
using DevExpress.Drawing;
using DevExpress.XtraBars.Ribbon;
using System.Data;
using System.Drawing;

namespace Dashboard_Coloring {
    public partial class Form1 : RibbonForm {
        public Form1() {
            InitializeComponent();
            dashboardDesigner1.CreateRibbon();

            // Create a color table that contains dimension values, measures and colors.
            DataTable colorTable = CreateColorTable();
            // Load a dashboard from the XML file.
            Dashboard dashboard = new Dashboard(); dashboard.LoadFromXml(@"..\..\Data\Dashboard.xml");
            IDashboardDataSource dataSource = dashboard.DataSources["dataSource1"];

            // Specify the coloring mode for the pie series, pie measures and chart argument.
            PieDashboardItem pie1 = (PieDashboardItem)dashboard.Items["pieDashboardItem1"];
            ChartDashboardItem chart1 = (ChartDashboardItem)dashboard.Items["chartDashboardItem1"];
            pie1.SeriesDimensions[0].ColoringMode = ColoringMode.Hue;
            pie1.ColoringOptions.MeasuresColoringMode = ColoringMode.Hue;
            chart1.Arguments[0].ColoringMode = ColoringMode.Hue;

            foreach (DataRow row in colorTable.Rows) {
                dashboard.ColorScheme.Add(CreateColorSchemeEntry(row, dataSource, false));
                dashboard.ColorScheme.Add(CreateColorSchemeEntry(row, dataSource, true));
            }
            dashboardDesigner1.Dashboard = dashboard;
        }

        // Create color scheme entries to map dimension values, measures and colors.
        private ColorSchemeEntry CreateColorSchemeEntry(DataRow colorSchemeRecord,
                                                        IDashboardDataSource dataSource,
                                                        bool includeMeasures) {
            DimensionDefinition categoryDefinition = new DimensionDefinition("CategoryName");
            DimensionDefinition countryDefinition = new DimensionDefinition("Country");
            MeasureDefinition priceDefinition = new MeasureDefinition("Extended Price");

            ColorSchemeEntry entry = new ColorSchemeEntry();
            entry.DimensionKeys.Add(new ColorSchemeDimensionKey(categoryDefinition,
                colorSchemeRecord["CategoryName"]));
            entry.DimensionKeys.Add(new ColorSchemeDimensionKey(countryDefinition,
                colorSchemeRecord["Country"]));
            if (includeMeasures)
                entry.MeasureKey = new ColorSchemeMeasureKey(priceDefinition);
            // Use a DashboardPaletteItem to define the color, a fill style (hatch), and line style.
            entry.ColorDefinition = new ColorDefinition(new DashboardPaletteItem(
                (Color)colorSchemeRecord["color"],
                (DXHatchStyle)colorSchemeRecord["hatch"],
                (DXDashStyle)colorSchemeRecord["line"]));
            entry.DataSource = dataSource;
            return entry;
        }

        private DataTable CreateColorTable() {
            DataTable colorTable = new DataTable();
            colorTable.Columns.Add("CategoryName", typeof(string));
            colorTable.Columns.Add("Country", typeof(string));
            colorTable.Columns.Add("measure", typeof(string));
            colorTable.Columns.Add("color", typeof(Color));
            colorTable.Columns.Add("hatch", typeof(DXHatchStyle));
            colorTable.Columns.Add("line", typeof(DXDashStyle));
            colorTable.Rows.Add("Beverages", "UK", "Extended Price", Color.Red, DXHatchStyle.DiagonalCross, DXDashStyle.Dash);
            colorTable.Rows.Add("Beverages", "USA", "Extended Price", Color.Green, DXHatchStyle.Sphere, DXDashStyle.Dot);
            return colorTable;
        }
    }
}

The image below shows the resulting dashboard with the customized color scheme:

WinForms Dashboard - Dashboard with a customized color scheme

See Also