Back to Devexpress

Measure Class

dashboard-devexpress-dot-dashboardcommon-ec27495c.md

latest10.6 KB
Original Source

Measure Class

A measure which is a DataItem whose values are summarized before they are used in the dashboard.

Namespace : DevExpress.DashboardCommon

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

NuGet Package : DevExpress.Dashboard.Core

Declaration

csharp
public class Measure :
    DataItem,
    IMeasureCalculationContext
vb
Public Class Measure
    Inherits DataItem
    Implements IMeasureCalculationContext

The following members return Measure objects:

Show 29 links

Remarks

The Measure is used to summarize data against grouped dimension values. These values can be of any type - numeric, date-time or string. In any case, the dashboard will calculate an appropriate summary function against measure values. You can also customize the data format settings that affect how summary values are displayed. In contrast to measures, a Dimension is used to provide discrete categorical information.

To learn more about dimensions and measures, see Measures and Dimensions.

Example

The following example binds a Chart dashboard item to data in code.

View Example

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

namespace Dashboard_CreateChart {
    public partial class Form1 : XtraForm {
        public Form1() {
            InitializeComponent();
        }
        private ChartDashboardItem CreateChart(DashboardObjectDataSource dataSource) {
            // Creates a chart dashboard item and specifies its data source.
            ChartDashboardItem chart = new ChartDashboardItem();
            chart.DataSource = dataSource;

            // Specifies the dimension used to provide data for arguments on a chart.
            chart.Arguments.Add(new Dimension("Sales Person", DateTimeGroupInterval.Year));

            // Specifies the dimension that provides data for chart series.
            chart.SeriesDimensions.Add(new Dimension("OrderDate"));

            // Adds a new chart pane to the chart's Panes collection.
            chart.Panes.Add(new ChartPane());
            // Creates a new series of the Bar type.
            SimpleSeries salesAmountSeries = new SimpleSeries(SimpleSeriesType.Bar);
            // Specifies the measure that provides data used to calculate
            // the Y-coordinate of data points.
            salesAmountSeries.Value = new Measure("Extended Price");
            // Adds created series to the pane's Series collection to display within this pane.
            chart.Panes[0].Series.Add(salesAmountSeries);

            chart.Panes.Add(new ChartPane());
            SimpleSeries taxesAmountSeries = new SimpleSeries(SimpleSeriesType.StackedBar);
            taxesAmountSeries.Value = new Measure("Quantity");
            chart.Panes[1].Series.Add(taxesAmountSeries);

            return chart;
        }
        private void Form1_Load(object sender, EventArgs e) {
            // Creates a dashboard and sets it as the currently opened dashboard in the dashboard viewer.
            dashboardViewer1.Dashboard = new Dashboard();

            // Creates a data source and adds it to the dashboard data source collection.
            DashboardObjectDataSource dataSource = new DashboardObjectDataSource();
            dataSource.DataSource = (new nwindDataSetTableAdapters.SalesPersonTableAdapter()).GetData();
            dashboardViewer1.Dashboard.DataSources.Add(dataSource);

            // Creates a chart dashboard item with the specified data source 
            // and adds it to the Items collection to display within the dashboard.
            ChartDashboardItem chart = CreateChart(dataSource);
            dashboardViewer1.Dashboard.Items.Add(chart);

            // Reloads data in the data sources.
            dashboardViewer1.ReloadData();
        }
    }
}
vb
Imports Microsoft.VisualBasic
Imports DevExpress.DashboardCommon
Imports DevExpress.XtraEditors
Imports System

Namespace Dashboard_CreateChart
    Partial Public Class Form1
        Inherits XtraForm
        Public Sub New()
            InitializeComponent()
        End Sub
        Private Function CreateChart(ByVal dataSource As DashboardObjectDataSource) As ChartDashboardItem
            ' Creates a chart dashboard item and specifies its data source.
            Dim chart As New ChartDashboardItem()
            chart.DataSource = dataSource

            ' Specifies the dimension used to provide data for arguments on a chart.
            chart.Arguments.Add(New Dimension("Sales Person", DateTimeGroupInterval.Year))

            ' Specifies the dimension that provides data for chart series.
            chart.SeriesDimensions.Add(New Dimension("OrderDate"))

            ' Adds a new chart pane to the chart's Panes collection.
            chart.Panes.Add(New ChartPane())
            ' Creates a new series of the Bar type.
            Dim salesAmountSeries As New SimpleSeries(SimpleSeriesType.Bar)
            ' Specifies the measure that provides data used to calculate
            ' the Y-coordinate of data points.
            salesAmountSeries.Value = New Measure("Extended Price")
            ' Adds created series to the pane's Series collection to display within this pane.
            chart.Panes(0).Series.Add(salesAmountSeries)

            chart.Panes.Add(New ChartPane())
            Dim taxesAmountSeries As New SimpleSeries(SimpleSeriesType.StackedBar)
            taxesAmountSeries.Value = New Measure("Quantity")
            chart.Panes(1).Series.Add(taxesAmountSeries)

            Return chart
        End Function
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
            ' Creates a dashboard and sets it as the currently opened dashboard in the dashboard viewer.
            dashboardViewer1.Dashboard = New Dashboard()

            ' Creates a data source and adds it to the dashboard data source collection.
            Dim dataSource As New DashboardObjectDataSource()
            dataSource.DataSource = (New nwindDataSetTableAdapters.SalesPersonTableAdapter()).GetData()
            dashboardViewer1.Dashboard.DataSources.Add(dataSource)

            ' Creates a chart dashboard item with the specified data source 
            ' and adds it to the Items collection to display within the dashboard.
            Dim chart As ChartDashboardItem = CreateChart(dataSource)
            dashboardViewer1.Dashboard.Items.Add(chart)

            ' Reloads data in the data sources.
            dashboardViewer1.ReloadData()
        End Sub
    End Class
End Namespace

The image below shows the resulting Chart dashboard item:

Inheritance

Object DataItem Measure

See Also

Measure Members

Bind Dashboard Items to Data in the Designer

DevExpress.DashboardCommon Namespace