ScatterChartItemFormatRule Class
A format rule that is used to apply conditional formatting to the Scatter Chart dashboard item.
Namespace: DevExpress.DashboardCommon
Assembly: DevExpress.Dashboard.v24.1.Core.dll
NuGet Package: DevExpress.Dashboard.Core
Declaration
Remarks
To add a format rule, create a ScatterChartItemFormatRule
object and specify its settings:
- Create a condition (a FormatConditionBase descendant), specify its settings, and assign it to the DashboardItemFormatRule.Condition property.
- Assign a data item (a measure/dimension) to the ChartItemFormatRuleBase.DataItem property. The data item’s value is used to calculate the condition.
- Add the format rule to the ScatterChartDashboardItem.FormatRules collection.
Set the ChartItemFormatRuleBase.ShowInLegend property to true to display a rule in a scatter chart’s legend. Use the ChartItemFormatRuleBase.DisplayName property to specify the rule’s caption that is displayed in a legend.
Example 1: Create a Value Format Rule
The following code snippet applies the Value format rule to the Scatter Chart dashboard item. The rule applies green to elements whose ExtendedPrice value exceeds 200,000.
public Form1() {
InitializeComponent();
ScatterChartDashboardItem scatterChart1 = (ScatterChartDashboardItem)dashboardDesigner1.Dashboard.Items["scatterChartDashboardItem1"];
AddFormatRulesToScatterChart(scatterChart1);
}
public void AddFormatRulesToScatterChart(ScatterChartDashboardItem scatterChart) {
ScatterChartItemFormatRule valueRule1 = new ScatterChartItemFormatRule();
valueRule1.DataItem = scatterChart.AxisYMeasure;
FormatConditionValue valueCondition1 = new FormatConditionValue(DashboardFormatCondition.Greater, 200000);
valueCondition1.StyleSettings = new ColorStyleSettings(Color.Green);
valueRule1.Condition = valueCondition1;
valueRule1.ShowInLegend = true;
valueRule1.DisplayName = "ExtendedPrice is greater than $200K";
scatterChart.FormatRules.Add(valueRule1);
}
Example 2: Create an Expression Format Rule
The following code snippet applies the Expression format rule to the Scatter Chart dashboard item. The rule colors elements if their corresponding X axis value exceeds 18 and Y axis value exceeds 7,000.
public Form1() {
InitializeComponent();
ScatterChartDashboardItem scatterChart1 = (ScatterChartDashboardItem)dashboardDesigner1.Dashboard.Items["scatterChartDashboardItem1"];
AddFormatRulesToScatterChart(scatterChart1);
}
public void AddFormatRulesToScatterChart(ScatterChartDashboardItem scatterChart) {
double unitCountThreshold = 7000;
double discountThreshold = 18;
ScatterChartItemFormatRule expressionRule1 = new ScatterChartItemFormatRule();
expressionRule1.DataItem = scatterChart.AxisYMeasure;
FormatConditionExpression formatCondition = new FormatConditionExpression();
formatCondition.Expression = $"{scatterChart.AxisYMeasure.UniqueId} > {unitCountThreshold} && {scatterChart.AxisXMeasure.UniqueId} > {discountThreshold}";
formatCondition.StyleSettings = new ColorStyleSettings(ColorTranslator.FromHtml("#14abb7"));
expressionRule1.Condition = formatCondition;
expressionRule1.ShowInLegend = true;
expressionRule1.DisplayName = "Discount amount from the quantity of products sold";
scatterChart.FormatRules.Add(expressionRule1);
}