dashboard-devexpress-dot-dashboardcommon-f1da6ba1.md
A format condition used to apply formatting using value ranges and a specified color gradient.
Namespace : DevExpress.DashboardCommon
Assembly : DevExpress.Dashboard.v25.2.Core.dll
NuGet Package : DevExpress.Dashboard.Core
public class FormatConditionRangeGradient :
FormatConditionRangeBase
Public Class FormatConditionRangeGradient
Inherits FormatConditionRangeBase
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.
Assign the resulting FormatConditionRangeGradient object to the DashboardItemFormatRule.Condition property.
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.
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;
}
}
}
Imports Microsoft.VisualBasic
Imports DevExpress.DashboardCommon
Imports DevExpress.DashboardWin
Imports DevExpress.XtraEditors
Imports System.Drawing
Namespace Grid_FormatRules
Partial Public Class GradientRangeConditionForm
Inherits XtraForm
Public Sub New()
InitializeComponent()
AddHandler dashboardViewer1.CustomizeDashboardTitle, AddressOf DashboardViewer1_CustomizeDashboardTitle
Dim dashboard As New Dashboard()
dashboard.LoadFromXml("..\..\Data\Dashboard.xml")
dashboardViewer1.Dashboard = dashboard
Dim grid As GridDashboardItem = CType(dashboard.Items("gridDashboardItem1"), GridDashboardItem)
Dim extendedPrice As GridMeasureColumn = CType(grid.Columns(1), GridMeasureColumn)
Dim rangeRule As New GridItemFormatRule(extendedPrice)
Dim rangeCondition As New FormatConditionRangeGradient(FormatConditionRangeGradientPredefinedType.RedBlue)
rangeRule.Condition = rangeCondition
grid.FormatRules.AddRange(rangeRule)
End Sub
Private Sub DashboardViewer1_CustomizeDashboardTitle(ByVal sender As Object, ByVal e As CustomizeDashboardTitleEventArgs)
Dim itemUpdate As New DashboardToolbarItem(Sub(args) UpdateFormatting()) With {.Caption = "Update Format Rule"}
e.Items.Add(itemUpdate)
End Sub
Private Sub UpdateFormatting()
Dim grid As GridDashboardItem = CType(dashboardViewer1.Dashboard.Items(0), GridDashboardItem)
Dim rangeRule As GridItemFormatRule = grid.FormatRules(0)
Dim rangeCondition As FormatConditionRangeGradient = CType(rangeRule.Condition, FormatConditionRangeGradient)
rangeCondition.Generate(New AppearanceSettings(Color.PaleVioletRed), New AppearanceSettings(Color.PaleGreen), 9)
Dim middleRange As RangeInfo = rangeCondition.RangeSet(4)
middleRange.StyleSettings = New AppearanceSettings(Color.SkyBlue)
rangeRule.Condition = rangeCondition
End Sub
End Class
End Namespace
Object FormatConditionBase FormatConditionRangeBase FormatConditionRangeGradient FormatConditionGradientRangeBar
See Also