Skip to main content
A newer version of this page is available. .

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.v21.2.UI.dll

NuGet Packages: DevExpress.Win.Charts, DevExpress.Win.Design

Declaration

public string SeriesDataMember { get; set; }

Property Value

Type Description
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 demonstrates how to bind 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, don’t forget to include all necessary assemblies to the References list of your project.

View Example

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);
        }
    }
}

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.

See Also