Skip to main content

FormatConditionRangeGradient Class

A format condition used to apply formatting using value ranges and a specified color gradient.

Namespace: DevExpress.DashboardCommon

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

Declaration

public class FormatConditionRangeGradient :
    FormatConditionRangeBase

Remarks

Range gradient conditions allow you to apply formatting using value ranges and a specified color gradient. You can specify whether an absolute or percent scale is used to define range boundaries using the FormatConditionRangeBase.ValueType property.

Use the following approaches to apply formatting using range gradient conditions.

  1. To use a predefined set of start/end colors to create a color gradient, pass the required FormatConditionRangeGradientPredefinedType enumeration value to the FormatConditionRangeGradient constructor or to the corresponding FormatConditionRangeGradient.Generate method overload.
  2. To use custom colors and a specified number of ranges to create color gradient, pass the required start/end colors (by initializing the AppearanceSettings object) and number of ranges to the FormatConditionRangeGradient constructor or to the corresponding FormatConditionRangeGradient.Generate method overload.
  3. To use custom colors and specified range boundaries to create a color gradient, pass the required start/end colors (by initializing the AppearanceSettings object) and an array of boundary values to the FormatConditionRangeGradient constructor or to the corresponding FormatConditionRangeGradient.Generate method overload. You can also specify boundary values by calling the FormatConditionRangeBase.SetValues method.
  4. To use custom range boundaries and the required style specified for each range, do the following.

Assign the resulting FormatConditionRangeGradient object to the DashboardItemFormatRule.Condition property.

Example

The Range Gradient condition (FormatConditionRangeGradient) allows you to use predefined color gradients to apply conditional formatting to different ranges of values.

This example demonstrates how to apply conditional formatting to Grid cells using the predefined Red-Blue color gradient. Click the Update Format Rule button to change start/end colors and the number of ranges in the color gradient. The third color in the middle of the color scale is also specified to generate a 3-color gradient.

View Example

using DevExpress.DashboardCommon;
using DevExpress.DashboardWin;
using DevExpress.XtraEditors;
using System.Drawing;

namespace Grid_FormatRules {
    public partial class GradientRangeConditionForm : XtraForm {
        public GradientRangeConditionForm() {
            InitializeComponent();
            dashboardViewer1.CustomizeDashboardTitle += DashboardViewer1_CustomizeDashboardTitle;
            Dashboard dashboard = new Dashboard();
            dashboard.LoadFromXml(@"..\..\Data\Dashboard.xml");
            dashboardViewer1.Dashboard = dashboard;
            GridDashboardItem grid = (GridDashboardItem)dashboard.Items["gridDashboardItem1"];
            GridMeasureColumn extendedPrice = (GridMeasureColumn)grid.Columns[1];

            GridItemFormatRule rangeRule = new GridItemFormatRule(extendedPrice);
            FormatConditionRangeGradient rangeCondition = 
                new FormatConditionRangeGradient(FormatConditionRangeGradientPredefinedType.RedBlue);
            rangeRule.Condition = rangeCondition;

            grid.FormatRules.AddRange(rangeRule);
        }

        private void DashboardViewer1_CustomizeDashboardTitle(object sender, CustomizeDashboardTitleEventArgs e)
        {
            DashboardToolbarItem itemUpdate = new DashboardToolbarItem((args) => UpdateFormatting()) {
                Caption = "Update Format Rule",
            };
            e.Items.Add(itemUpdate);
        }

        private void UpdateFormatting() {
            GridDashboardItem grid = (GridDashboardItem)dashboardViewer1.Dashboard.Items[0];
            GridItemFormatRule rangeRule = grid.FormatRules[0];

            FormatConditionRangeGradient rangeCondition = 
                (FormatConditionRangeGradient)rangeRule.Condition;
            rangeCondition.Generate(new AppearanceSettings(Color.PaleVioletRed), 
                                    new AppearanceSettings(Color.PaleGreen), 9);
            RangeInfo middleRange = rangeCondition.RangeSet[4];
            middleRange.StyleSettings = new AppearanceSettings(Color.SkyBlue);

            rangeRule.Condition = rangeCondition;
        }
    }
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the FormatConditionRangeGradient class.

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