Back to Devexpress

FormatConditionAverage Class

dashboard-devexpress-dot-dashboardcommon-ede426bd.md

latest8.2 KB
Original Source

FormatConditionAverage Class

A format condition used to apply formatting according to the average value.

Namespace : DevExpress.DashboardCommon

Assembly : DevExpress.Dashboard.v25.2.Core.dll

NuGet Package : DevExpress.Dashboard.Core

Declaration

csharp
public class FormatConditionAverage :
    FormatConditionStyleBase
vb
Public Class FormatConditionAverage
    Inherits FormatConditionStyleBase

Remarks

To create a format condition to apply formatting to values compared to the average, do the following.

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

Example

The Top-Bottom (FormatConditionTopBottom) format conditions allow you to highlight a specific number of topmost/bottommost values. This example shows how to apply conditional formatting to the specified number of top/bottom values. The number of values can be specified as an absolute value or a percentage of all values.

The Average format condition (FormatConditionAverage) is used to highlight values above or below an average value.

View Example

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

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

            GridItemFormatRule topRule = new GridItemFormatRule(extendedPrice, salesPerson);
            FormatConditionTopBottom topCondition = new FormatConditionTopBottom();
            topCondition.TopBottom = DashboardFormatConditionTopBottomType.Top;
            topCondition.RankType = DashboardFormatConditionValueType.Number;
            topCondition.Rank = 3;
            topCondition.StyleSettings = new IconSettings(FormatConditionIconType.IndicatorGreenCheck);
            topRule.Condition = topCondition;

            GridItemFormatRule bottomRule = new GridItemFormatRule(extendedPrice, salesPerson);
            FormatConditionTopBottom bottomCondition = new FormatConditionTopBottom();
            bottomCondition.TopBottom = DashboardFormatConditionTopBottomType.Bottom;
            bottomCondition.RankType = DashboardFormatConditionValueType.Percent;
            bottomCondition.Rank = 40;
            bottomCondition.StyleSettings = new IconSettings(FormatConditionIconType.IndicatorRedFlag);
            bottomRule.Condition = bottomCondition;

            GridItemFormatRule aboveAverageRule = new GridItemFormatRule(extendedPrice);
            FormatConditionAverage aboveAverageCondition = new FormatConditionAverage();
            aboveAverageCondition.AverageType = DashboardFormatConditionAboveBelowType.Above;
            aboveAverageCondition.StyleSettings = 
                new AppearanceSettings(Color.Green, FontStyle.Underline);
            aboveAverageRule.Condition = aboveAverageCondition;

            GridItemFormatRule belowAverageRule = new GridItemFormatRule(extendedPrice);
            FormatConditionAverage belowAverageCondition = new FormatConditionAverage();
            belowAverageCondition.AverageType = DashboardFormatConditionAboveBelowType.Below;
            belowAverageCondition.StyleSettings = 
                new AppearanceSettings(Color.Orange, FontStyle.Underline);
            belowAverageRule.Condition = belowAverageCondition;

            grid.FormatRules.AddRange(topRule, bottomRule, aboveAverageRule, belowAverageRule);
        }
    }
}
vb
Imports Microsoft.VisualBasic
Imports DevExpress.DashboardCommon
Imports DevExpress.XtraEditors
Imports System.Drawing

Namespace Grid_FormatRules
    Partial Public Class TopAverageConditionForm
        Inherits XtraForm
        Public Sub New()
            InitializeComponent()
            Dim dashboard As New Dashboard()
            dashboard.LoadFromXml("..\..\Data\Dashboard.xml")
            dashboardViewer1.Dashboard = dashboard
            Dim grid As GridDashboardItem = CType(dashboard.Items("gridDashboardItem1"), GridDashboardItem)
            Dim salesPerson As GridDimensionColumn = CType(grid.Columns(0), GridDimensionColumn)
            Dim extendedPrice As GridMeasureColumn = CType(grid.Columns(1), GridMeasureColumn)

            Dim topRule As New GridItemFormatRule(extendedPrice, salesPerson)
            Dim topCondition As New FormatConditionTopBottom()
            topCondition.TopBottom = DashboardFormatConditionTopBottomType.Top
            topCondition.RankType = DashboardFormatConditionValueType.Number
            topCondition.Rank = 3
            topCondition.StyleSettings = New IconSettings(FormatConditionIconType.IndicatorGreenCheck)
            topRule.Condition = topCondition

            Dim bottomRule As New GridItemFormatRule(extendedPrice, salesPerson)
            Dim bottomCondition As New FormatConditionTopBottom()
            bottomCondition.TopBottom = DashboardFormatConditionTopBottomType.Bottom
            bottomCondition.RankType = DashboardFormatConditionValueType.Percent
            bottomCondition.Rank = 40
            bottomCondition.StyleSettings = New IconSettings(FormatConditionIconType.IndicatorRedFlag)
            bottomRule.Condition = bottomCondition

            Dim aboveAverageRule As New GridItemFormatRule(extendedPrice)
            Dim aboveAverageCondition As New FormatConditionAverage()
            aboveAverageCondition.AverageType = DashboardFormatConditionAboveBelowType.Above
            aboveAverageCondition.StyleSettings = New AppearanceSettings(Color.Green, FontStyle.Underline)
            aboveAverageRule.Condition = aboveAverageCondition

            Dim belowAverageRule As New GridItemFormatRule(extendedPrice)
            Dim belowAverageCondition As New FormatConditionAverage()
            belowAverageCondition.AverageType = DashboardFormatConditionAboveBelowType.Below
            belowAverageCondition.StyleSettings = New AppearanceSettings(Color.Orange, FontStyle.Underline)
            belowAverageRule.Condition = belowAverageCondition

            grid.FormatRules.AddRange(topRule, bottomRule, aboveAverageRule, belowAverageRule)
        End Sub
    End Class
End Namespace

Inheritance

Object FormatConditionBase FormatConditionStyleBase FormatConditionAverage

See Also

FormatConditionAverage Members

DevExpress.DashboardCommon Namespace