Example E3
Visible to All Users

How to bind a chart to data using series templates

Files to look at:

The following example demonstrates how to bind a chart to data at runtime using series templates.

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

Form1.cs(vb)
C#
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); } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.