Skip to main content
A newer version of this page is available. .
All docs
V23.1

ChartCustomIndicator Class

A custom indicator in a chart dashboard item.

Namespace: DevExpress.DashboardCommon

Assembly: DevExpress.Dashboard.v23.1.Core.dll

NuGet Packages: DevExpress.Dashboard.Core, DevExpress.Win.Dashboard.Design

Declaration

public class ChartCustomIndicator :
    ChartIndicatorBase

Remarks

The following example shows how to create a custom “Moving Average” indicator for a chart dashboard item:

Custom Moving Indicator

View Example

Create a Custom Indicator Type

Create a ChartCustomIndicator descendant (the MovingIndicator class in this example). MovingIndicator accepts a collection of data points, evaluates the values, and returns the resulting points. These points are used to draw the indicator.

Register the Custom Indicator Type

Register the MovingIndicator type in IndicatorFactory to make this type available as the indicator type in the Trend Indicators editor.

Add the indicator type to the Trend indicator editor

Call the Register method in your application before you save and load a dashboard to serialize and deserialize the indicator within the dashboard XML.

Configure and Display the Indicator

Create an instance of MovingIndicator and specify the indicator settings:

This property is required to display the indicator in the Chart dashboard item when you launch the application:

Value
Specifies the measure data item that is used to calculate the trend indicator.

If you do not specify the following properties, their default values are used:

Name
Specifies the name of the trend indicator within the indicators collection.
ValueLevel
Gets or sets the value that specifies which series point value should be used to calculate the indicator.
ShowInLegend
Specifies whether to display the trend indicator in the legend.
LegendText
Specifies the text that identifies the trend indicator within the legend.
Thickness
Specifies the thickness of the indicator line.
Color
Specifies the trend indicator’s color.
DashStyle
Specifies the dash style used to paint the line.
Visible
Specifies whether to display the trend indicator.

Add MovingIndicator to the chart indicators collection to display the configured indicator in the UI.

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using DevExpress.DashboardCommon;
using DevExpress.DashboardCommon.ViewerData;

namespace WinForm {
    public partial class FormDesigner : Form {
        public FormDesigner() {
            try {
                IndicatorFactory.Register<MovingIndicator>("Moving average");
            } catch(Exception e) {
                MessageBox.Show(e.Message);
            }
            InitializeComponent();
            var dashboard = new Dashboard1();
            ChartDashboardItem chartItem = dashboard.Items.First(x => x.ComponentName == "chartDashboardItem1") as ChartDashboardItem;
            MovingIndicator trendLine = new MovingIndicator() {
                Name = "MovingLine1",
                Value = "DataItem1",
                ValueLevel = DevExpress.XtraCharts.ValueLevel.Value,
                Color = Color.Orange,
                LegendText = "Moving Average"
            };
            chartItem.Indicators.Add(trendLine);
            dashboardDesigner.Dashboard = dashboard;
            dashboardDesigner.CreateRibbon();
            dashboardDesigner.CreateCustomItemBars();
        }
    }

    public class MovingIndicator : ChartCustomIndicator {
        protected override Dictionary<AxisPoint, object> Calculate(Dictionary<AxisPoint, decimal?> values) {
            var items = new Dictionary<AxisPoint, object>(values.Count);

            var sum = decimal.Zero;
            var count = 0;
            foreach(KeyValuePair<AxisPoint, decimal?> point in values) {
                if(count == 0) {
                    items.Add(point.Key, null);
                } else {
                    items.Add(point.Key, sum / count);
                }
                sum += point.Value ?? 0;
                count++;
            }

            return items;
        }
    }
}

The following image illustrates the result:

Moving Indicator in the Trend Indicators editor

More Examples

View Example: Dashboard for ASP.NET Core - Custom Trend Indicator

Inheritance

Object
ChartIndicatorBase
ChartCustomIndicator
See Also