Back to Devexpress

ChartItemFormatRule Class

dashboard-devexpress-dot-dashboardcommon-34332ad1.md

latest5.7 KB
Original Source

ChartItemFormatRule Class

A format rule that is used to apply conditional formatting to the Chart dashboard item.

Namespace : DevExpress.DashboardCommon

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

NuGet Package : DevExpress.Dashboard.Core

Declaration

csharp
public class ChartItemFormatRule :
    ChartItemFormatRuleBase
vb
Public Class ChartItemFormatRule
    Inherits ChartItemFormatRuleBase

Remarks

Create a ChartItemFormatRule object and specify its settings to add a format rule:

Set ChartItemFormatRuleBase.ShowInLegend property to true to display a rule in a chart’s legend. Use the ChartItemFormatRuleBase.DisplayName property to specify the rule’s caption that is displayed in a legend.

The following code snippet shows how to apply the Gradient Range and Value rules to the Chart Dashboard item:

csharp
public Form1() {
    InitializeComponent();
    ChartDashboardItem chart1 = (ChartDashboardItem)dashboardDesigner1.Dashboard.Items["chartDashboardItem1"];
    ChartDashboardItem chart2 = (ChartDashboardItem)dashboardDesigner1.Dashboard.Items["chartDashboardItem2"];
    AddFormatRulesToBarSeries(chart1);
    AddFormatRulesToLineSeries(chart2);
}
public void AddFormatRulesToBarSeries(ChartDashboardItem chart) {
    SimpleSeries series = chart.Panes[0].Series[0] as SimpleSeries;
    ChartItemFormatRule gradientRule = new ChartItemFormatRule(series.Value, series);
    FormatConditionRangeGradient condition = new FormatConditionRangeGradient(FormatConditionRangeGradientPredefinedType.RedBlue);
    gradientRule.Condition = condition;
    gradientRule.ShowInLegend = false;
    chart.FormatRules.Add(gradientRule);
}
public void AddFormatRulesToLineSeries(ChartDashboardItem chart) {
    SimpleSeries series = chart.Panes[0].Series[0] as SimpleSeries;
    ChartItemFormatRule valueRule1 = new ChartItemFormatRule(series.Value, series);
    FormatConditionValue valueCondition1 = new FormatConditionValue(DashboardFormatCondition.Greater, 3000);
    valueCondition1.StyleSettings = new ColorStyleSettings(Color.Green);
    valueRule1.Condition = valueCondition1;
    valueRule1.ShowInLegend = true;
    valueRule1.Description = "UnitPrice greater than $3K";
    chart.FormatRules.Add(valueRule1);
}
vb
Public Sub New()
    InitializeComponent()
    Dim chart1 As ChartDashboardItem = CType(dashboardDesigner1.Dashboard.Items("chartDashboardItem1"), ChartDashboardItem)
    Dim chart2 As ChartDashboardItem = CType(dashboardDesigner1.Dashboard.Items("chartDashboardItem2"), ChartDashboardItem)
    AddFormatRulesToBarSeries(chart1)
    AddFormatRulesToLineSeries(chart2)
End Sub
Public Sub AddFormatRulesToBarSeries(ByVal chart As ChartDashboardItem)
    Dim series As SimpleSeries = TryCast(chart.Panes(0).Series(0), SimpleSeries)
    Dim gradientRule As New ChartItemFormatRule(series.Value, series)
    Dim condition As New FormatConditionRangeGradient(FormatConditionRangeGradientPredefinedType.RedBlue)
    gradientRule.Condition = condition
    gradientRule.ShowInLegend = False
    chart.FormatRules.Add(gradientRule)
End Sub
Public Sub AddFormatRulesToLineSeries(ByVal chart As ChartDashboardItem)
    Dim series As SimpleSeries = TryCast(chart.Panes(0).Series(0), SimpleSeries)
    Dim valueRule1 As New ChartItemFormatRule(series.Value, series)
    Dim valueCondition1 As New FormatConditionValue(DashboardFormatCondition.Greater, 3000)
    valueCondition1.StyleSettings = New ColorStyleSettings(Color.Green)
    valueRule1.Condition = valueCondition1
    valueRule1.ShowInLegend = True
    valueRule1.Description = "UnitPrice greater than $3K"
    chart.FormatRules.Add(valueRule1)
End Sub

Inheritance

Object DashboardItemFormatRule ChartItemFormatRuleBase ChartItemFormatRule

See Also

ChartItemFormatRule Members

DevExpress.DashboardCommon Namespace