Skip to main content

How to: Bind a Chart to an XML Data Source using a Complex Data Path

The following example demonstrates how to bind a chart to using a complex data path with dots.

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. Then, set the Series.ArgumentDataMember and Series.ValueDataMember properties to the complex names of XML elements (containing a path to a specific XML node) that should provide data for arguments and value.

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

<Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts" Title="Window1" Height="491" Width="637">
    <Window.Resources>
        <ResourceDictionary>
            <XmlDataProvider x:Key="contacts" Source="Contacts.xml" XPath="/NewDataSet">
            </XmlDataProvider>
        </ResourceDictionary>
    </Window.Resources>
        <Grid>
        <dxc:ChartControl Name="chartControl1">
            <dxc:ChartControl.Diagram>
                <dxc:XYDiagram2D>
                    <dxc:XYDiagram2D.Series>
                        <dxc:BarSideBySideSeries2D DataSource="{StaticResource contacts}" ArgumentDataMember="Contacts.LastName" ValueDataMember="Contacts.PaymentAmount" />
                    </dxc:XYDiagram2D.Series>
                </dxc:XYDiagram2D>
            </dxc:ChartControl.Diagram>
        </dxc:ChartControl>
    </Grid>
</Window>