ValueDataMemberCollection Class
Represents a collection that stores the names of the data fields that hold point data values.
Namespace: DevExpress.XtraCharts
Assembly: DevExpress.XtraCharts.v24.2.dll
Declaration
[ListBindable(false)]
public class ValueDataMemberCollection :
CollectionBase,
IOwnedElement
Related API Members
The following members return ValueDataMemberCollection objects:
Remarks
When a series is data bound, it obtains its point values (arguments and data values) from the specific data fields of the corresponding data source. Each point is defined by one argument value and one or more data values (for instance, four data values - low, high, open and close - are required to plot a stock point). While the SeriesBase.ArgumentDataMember property specifies a data field containing argument values, the SeriesBase.ValueDataMembers property provides access to a collection that stores the names of the data fields that hold the data values of series points. This collection is represented by an instance of the ValueDataMemberCollection class.
The ValueDataMemberCollection class extends the base collection functionality inherited from the CollectionBase class by implementing the following members: the ValueDataMemberCollection.Item property which provides access to collection items using indexer notation, the ValueDataMemberCollection.AddRange method which allows an array of field names to be appended to the collection and the ValueDataMemberCollection.Assign method which copies all the elements in a specific collection object to the collection.
Note that a number of items within a collection represented by the ValueDataMemberCollection class depends upon the series type. For most series types (for instance, the bar, point, pie series), this collection contains only one item that specifies the data field which point data values should be obtained from. For series which represent price data (such as the stock, candle stick series) and whose points are defined by several price values (low, high, open and close), this collection holds the corresponding number of items (four, in particular). These items are listed in the following predefined order: the field name for the Low value, the field name for the High value, the field name for the Open value and the field name for the Close value.
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.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-bind-a-chart-to-data-using-series-templates-e3
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);
}
}
}