Skip to main content

How to: Bind a Chart to an XML Data Source using the XPath Property

The following example demonstrates how to bind a chart to an XML data source using the XPath property.

To accomplish this task, it is necessary to add an XmlDataProvider object to a collection of the window’s static resources, then assign this resource to a series’ Series.DataSource property using the XPath key to define the path to a specific XML node. Then, set the Series.ArgumentDataMember and Series.ValueDataMember properties to the names of XML elements that should provide data for arguments and values.

Note that this approach to data binding is done completely in XAML, and no code-behind file is required.

View Example

<Window x:Class="WpfApplication1.Window1" xmlns="" xmlns:x="" xmlns:dxc="" Title="Window1" Height="491" Width="637">
            <XmlDataProvider x:Key="contacts" Source="Contacts.xml" XPath="/NewDataSet">
        <dxc:ChartControl Name="chartControl1">
                        <dxc:BarSideBySideSeries2D DataSource="{Binding Source={StaticResource contacts}, XPath=Contacts}" ArgumentDataMember="LastName" ValueDataMember="PaymentAmount" />