How to: Bind a Chart to an XML Data Source
- 2 minutes to read
This tutorial demonstrates how a chart can be bound to an XML data source. In this example, we’ll bind a chart to the Departments.xml file, shipped with the XtraCharts suite and located in the directory, where you installed DevExpress demos.
To bind a chart to an XML data source, do the following.
- Start Microsoft Visual Studio, and create a new Windows Forms Application, or open an existing one.
- Add a chart to the form.
- Add Bar series to the chart.
Handle the Form1_Load event using the following code.
using System; using System.Data; using System.Windows.Forms; using DevExpress.XtraCharts; // ... private void Form1_Load(object sender, EventArgs e) { // Create a DataSet instance and, make it read the xml file. DataSet ds = new DataSet(); ds.ReadXml(@"..\..\Departments.xml"); // Specify the dataset as the chart's data source. chartControl1.DataSource = ds; // Specify the argument and value data members for the series. chartControl1.Series[0].ArgumentDataMember = "Table.Department"; chartControl1.Series[0].ValueDataMembers.AddRange(new string[] { "Table.Budget" }); // Define an appropriate scale type for the series points' values. chartControl1.Series[0].ValueScaleType = ScaleType.Numerical; }
The result is shown in the following image.