Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

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.

  1. Start Microsoft Visual Studio, and create a new Windows Forms Application, or open an existing one.
  2. Add a chart to the form.
  3. Add Bar series to the chart.
  4. 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.

HowTo_XMLdataSource