Back to Devexpress

ChartControl.SeriesDataMember Property

windowsforms-devexpress-dot-xtracharts-dot-chartcontrol-1777f9e8.md

latest13.2 KB
Original Source

ChartControl.SeriesDataMember Property

Gets or sets the name of the data field that contains names for automatically generated series.

Namespace : DevExpress.XtraCharts

Assembly : DevExpress.XtraCharts.v25.2.UI.dll

NuGet Package : DevExpress.Win.Charts

Declaration

csharp
public string SeriesDataMember { get; set; }
vb
Public Property SeriesDataMember As String

Property Value

TypeDescription
String

A String value that specifies the data field’s name.

|

Remarks

When chart binding is used to automatically generate series within a chart control based upon the data obtained from the associated data source (ChartControl.DataSource) a rule needs to be defined that helps the chart control recognize the data records whose values are used to construct individual series objects. For this purpose, the SeriesDataMember property can be used. It specifies the data field whose values are taken into account when series objects are automatically created and populated.

Each automatically generated series gets its name from the data field specified by the SeriesDataMember property. This name is used to identify a series within the chart control’s legend, for instance. The names of all automatically generated series can be supplemented with the same prefix and postfix defined by the settings available via the ChartControl.SeriesNameTemplate property.

The template settings for the dynamically created series are defined by the specific properties available via the ChartControl.SeriesTemplate property of a chart control. In particular, the SeriesBase.ArgumentDataMember and SeriesBase.ValueDataMembers properties specify the data fields from which the arguments and data values of the series data points are obtained.

Note that if the SeriesDataMember property is not set for a chart control, the chart control can’t automatically generate series even if the SeriesBase.ArgumentDataMember and SeriesBase.ValueDataMembers properties are defined.

Example

The following example binds a chart to data at runtime using series templates. It uses the same approach as the design-time example, but another data table is generated in this code to simplify the example. For this example to work correctly, do not forget to include all necessary assemblies to the References list of your project.

View Example

csharp
using System;
using System.Data;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...

namespace BindUsingTemplatesRuntimeCS {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        private DataTable CreateChartData() {
            // Create an empty table.
            DataTable table = new DataTable("Table1");

            // Add three columns to the table.
            table.Columns.Add("Month", typeof(String));
            table.Columns.Add("Section", typeof(String));
            table.Columns.Add("Value", typeof(Int32));

            // Add data rows to the table.
            table.Rows.Add(new object[] { "Jan", "Section1", 10 });
            table.Rows.Add(new object[] { "Jan", "Section2", 20 });
            table.Rows.Add(new object[] { "Feb", "Section1", 20 });
            table.Rows.Add(new object[] { "Feb", "Section2", 30 });
            table.Rows.Add(new object[] { "March", "Section1", 15 });
            table.Rows.Add(new object[] { "March", "Section2", 25 });

            return table;
        }

        private void Form1_Load(object sender, EventArgs e) {
            // Create a chart.
            ChartControl chart = new ChartControl();

            // Generate a data table and bind the chart to it.
            chart.DataSource = CreateChartData();

            // Specify data members to bind the chart's series template.
            chart.SeriesDataMember = "Month";
            chart.SeriesTemplate.ArgumentDataMember = "Section";
            chart.SeriesTemplate.ValueDataMembers.AddRange(new string[] {"Value"});

            // Specify the template's series view.
            chart.SeriesTemplate.View = new StackedBarSeriesView();

            // Specify the template's name prefix.
            chart.SeriesNameTemplate.BeginText = "Month: ";

            // Dock the chart into its parent, and add it to the current form.
            chart.Dock = DockStyle.Fill;
            this.Controls.Add(chart);
        }
    }
}
vb
Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...

Namespace BindUsingTemplatesRuntimeCS
    Partial Public Class Form1
        Inherits Form
        Public Sub New()
            InitializeComponent()
        End Sub

        Private Function CreateChartData() As DataTable
            ' Create an empty table.
            Dim table As New DataTable("Table1")

            ' Add three columns to the table.
            table.Columns.Add("Month", GetType(String))
            table.Columns.Add("Section", GetType(String))
            table.Columns.Add("Value", GetType(Int32))

            ' Add data rows to the table.
            table.Rows.Add(New Object() { "Jan", "Section1", 10 })
            table.Rows.Add(New Object() { "Jan", "Section2", 20 })
            table.Rows.Add(New Object() { "Feb", "Section1", 20 })
            table.Rows.Add(New Object() { "Feb", "Section2", 30 })
            table.Rows.Add(New Object() { "March", "Section1", 15 })
            table.Rows.Add(New Object() { "March", "Section2", 25 })

            Return table
        End Function

        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
            ' Create a chart.
            Dim chart As New ChartControl()

            ' Generate a data table and bind the chart to it.
            chart.DataSource = CreateChartData()

            ' Specify data members to bind the chart's series template.
            chart.SeriesDataMember = "Month"
            chart.SeriesTemplate.ArgumentDataMember = "Section"
            chart.SeriesTemplate.ValueDataMembers.AddRange(New String() {"Value"})

            ' Specify the template's series view.
            chart.SeriesTemplate.View = New StackedBarSeriesView()

            ' Specify the template's name prefix.
            chart.SeriesNameTemplate.BeginText = "Month: "

            ' Dock the chart into its parent, and add it to the current form.
            chart.Dock = DockStyle.Fill
            Me.Controls.Add(chart)
        End Sub
    End Class
End Namespace

The following code snippets (auto-collected from DevExpress Examples) contain references to the SeriesDataMember property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-visualize-data-grid-rows-in-a-chart/CS/ControlRowSourceSample/MainForm.cs#L24

csharp
// Specify chart properties that configures series to display.
chartControl.SeriesDataMember = "State";

winforms-charts-sort-stacked-bars-by-total-values-with-qualitativescalecomparer/CS/Form1.cs#L16

csharp
chartControl1.DataSource = CreateDataSource();
chartControl1.SeriesDataMember = "Series";
SeriesTemplate seriesTemplate = chartControl1.SeriesTemplate;

winforms-charts-configure-settings-for-template-series-and-series-added-manually/CS/series-base-example/Form1.cs#L20

csharp
chart.DataSource = GetSeriesTemplateData();
chart.SeriesDataMember = "Region";
chart.SeriesTemplate.View = new LineSeriesView();

winforms-chart-draw-a-custom-legend-marker-for-a-series-point/CS/CustomSeriesPointDrawingSample/Form1.cs#L49

csharp
}
chart.SeriesDataMember = "Year";
chart.SeriesTemplate.ArgumentDataMember = "Employee";

winforms-chart-draw-a-custom-legend-marker-for-a-series/CS/CustomDrawingSample/Form1.cs#L43

csharp
chart.SeriesDataMember = "Employee.FullName";
chart.SeriesTemplate.ArgumentDataMember = "OrderDate";

winforms-visualize-data-grid-rows-in-a-chart/VB/ControlRowSourceSample/MainForm.vb#L23

vb
' Specify chart properties that configures series to display.
chartControl.SeriesDataMember = "State"
Dim seriesTemplate As SeriesBase = chartControl.SeriesTemplate

winforms-charts-sort-stacked-bars-by-total-values-with-qualitativescalecomparer/VB/Form1.vb#L17

vb
chartControl1.DataSource = CreateDataSource()
chartControl1.SeriesDataMember = "Series"
Dim seriesTemplate As SeriesTemplate = chartControl1.SeriesTemplate

winforms-charts-configure-settings-for-template-series-and-series-added-manually/VB/series-base-example/Form1.vb#L22

vb
chart.DataSource = GetSeriesTemplateData()
chart.SeriesDataMember = "Region"
chart.SeriesTemplate.View = New LineSeriesView()

winforms-chart-draw-a-custom-legend-marker-for-a-series-point/VB/CustomSeriesPointDrawingSample/Form1.vb#L54

vb
Me.chart.SeriesDataMember = "Year"
Me.chart.SeriesTemplate.ArgumentDataMember = "Employee"

winforms-chart-draw-a-custom-legend-marker-for-a-series/VB/CustomDrawingSample/Form1.vb#L48

vb
chart.SeriesDataMember = "Employee.FullName"
chart.SeriesTemplate.ArgumentDataMember = "OrderDate"

See Also

DataSource

SeriesNameTemplate

ArgumentDataMember

ValueDataMembers

ChartControl Class

ChartControl Members

DevExpress.XtraCharts Namespace