FormatConditionColorRangeBar Class
A format condition used to visualize numeric values using bars whose colors are contained in the specified color set.
Namespace: DevExpress.DashboardCommon
Assembly: DevExpress.Dashboard.v24.1.Core.dll
NuGet Package: DevExpress.Dashboard.Core
Declaration
Remarks
Range conditions allow you to apply formatting using a predefined set of value ranges and corresponding style settings.
To create a format condition to display bars of different colors with lengths proportional to corresponding values, use the following approaches.
- To use a predefined set of colors, pass the required FormatConditionRangeSetPredefinedType enumeration value to the FormatConditionColorRangeBar constructor or call the FormatConditionColorRangeBar.Generate method.
To use a predefined set of colors and custom range boundaries, do the following.
- Pass the required FormatConditionRangeSetPredefinedType enumeration value to the FormatConditionColorRangeBar constructor or call the FormatConditionColorRangeBar.Generate method.
- Specify the type of range boundaries using the FormatConditionRangeBase.ValueType property and assign the required boundary values using the FormatConditionRangeBase.SetValues property.
- If necessary, change the comparison logic using the FormatConditionRangeBase.SetValueComparison property.
To use custom range boundaries and the required style specified for each range, do the following.
- Specify whether an absolute or percent scale is used to define range boundaries using the FormatConditionRangeBase.ValueType property.
- Create the required number of RangeInfo objects that are the ranges containing boundary values (the RangeInfo.Value property), a comparison logic (RangeInfo.ValueComparison) and style setting applied to range values (assign the BarStyleSettings object to the RangeInfo.StyleSettings property).
- Add initialized RangeInfo objects to the FormatConditionRangeBase.RangeSet collection.
Assign the resulting FormatConditionColorRangeBar object to the DashboardItemFormatRule.Condition property.
Example
The Bar Color Ranges condition (FormatConditionColorRangeBar
) allows you to visualize numeric values using bars whose colors are contained in the specified color set.
This example shows how to display colored bars within Grid cells. Click the Update Format Rule button to change the number of ranges, specify new range boundaries and customize colors mapped to existing ranges.
using DevExpress.DashboardCommon;
using DevExpress.DashboardWin;
using DevExpress.XtraEditors;
namespace Grid_FormatRules {
public partial class RangeColorBarConditionForm : XtraForm {
public RangeColorBarConditionForm() {
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);
FormatConditionColorRangeBar rangeBarCondition =
new FormatConditionColorRangeBar(FormatConditionRangeSetPredefinedType.ColorsRedGreenBlue);
rangeBarCondition.BarOptions.ShowBarOnly = true;
rangeRule.Condition = rangeBarCondition;
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["gridDashboardItem1"];
GridItemFormatRule rangeRule = grid.FormatRules[0];
FormatConditionColorRangeBar rangeBarCondition = (FormatConditionColorRangeBar)rangeRule.Condition;
RangeInfo range3 = rangeBarCondition.RangeSet[2];
range3.Value = 50;
range3.StyleSettings =
new BarStyleSettings(FormatConditionAppearanceType.GradientGreen);
RangeInfo range4 = new RangeInfo();
range4.Value = 75;
range4.StyleSettings =
new BarStyleSettings(FormatConditionAppearanceType.GradientBlue);
rangeBarCondition.RangeSet.Add(range4);
rangeRule.Condition = rangeBarCondition;
}
}
}