Skip to main content
A newer version of this page is available. .

Lesson 3 - Create a Funnel Chart

  • 4 minutes to read

This lesson explains how to create a Funnel chart, bind it to data, add a legend, and customize funnel point labels.

DevExpress WinUI | Get Started - Funnel Chart

Before you proceed, review the following topics:

Create a New Project

Create a new Blank App, Packaged with Windows Application Packaging Project (WinUI 3 in Desktop) project and add the DevExpress.WinUI NuGet package.

Refer to the following topic for more information on how to create a new project: DevExpress WinUI Controls: Get Started.

Add a Data Model

In the MainWindow.xaml.cs, add a new DataPoint class that defines a data model:

public class DataPoint {
    public string Argument { get; set; }
    public double Value { get; set; }
}

Add a View Model

In the MainWindow.xaml.cs, add a new ChartViewModel class that specifies a view model:

public class ChartViewModel : ViewModelBase {
    public ChartViewModel() {
        List<DataPoint> dataPoints = new List<DataPoint> {
            new DataPoint() { Argument = "Visited a Website",    Value = 9152 },
            new DataPoint() { Argument = "Downloaded a Trial",   Value = 6870 },
            new DataPoint() { Argument = "Contacted to Support", Value = 5121 },
            new DataPoint() { Argument = "Subscribed",           Value = 2224 },
            new DataPoint() { Argument = "Renewed",              Value = 1670 }
        };
        DataPoints = dataPoints;
    }
    public List<DataPoint> DataPoints { get; }
}

In the MainWindow.xaml, specify the window’s data context as follows:

<Window>
    <Grid>
        <Grid.DataContext>
            <local:ChartViewModel/>
        </Grid.DataContext>
        <!--...-->
    </Grid>
</Window>

Add the FunnelChart Control to the Window

Add a FunnelChart instance to the window:

<Window
    xmlns:Charts="using:DevExpress.WinUI.Charts">
    <Grid>
    <!--...-->
        <Charts:FunnelChart>
            <!--...-->
        </Charts:FunnelChart>
    </Grid>
</Window>

Add a Series and Bind it to Data

<Charts:FunnelChart>
    <Charts:FunnelChart.Series>
        <Charts:FunnelSeries>
            <Charts:FunnelSeries.Data>
                <Charts:DataSource PointSource="{Binding DataPoints}"
                                   ArgumentDataMember="Argument"
                                   ValueDataMember="Value"/>
            </Charts:FunnelSeries.Data>
            <Charts:FunnelSeries.View>
                <Charts:FunnelSeriesView PointDistance="10" 
                                         ShowLabels="True"
                                         LabelPattern="{}{A}: {VP:p2}"
                                         LabelPosition="LeftColumn" 
                                         Title="Website Visitors"
                                         LegendPointPattern="{}{A}: {V}">
                    <Charts:FunnelSeriesView.TitleContentTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding}" 
                                       FontSize="18" 
                                       Margin="20"/>
                        </DataTemplate>
                    </Charts:FunnelSeriesView.TitleContentTemplate>
                </Charts:FunnelSeriesView>
            </Charts:FunnelSeries.View>
        </Charts:FunnelSeries>
    </Charts:FunnelChart.Series>
</Charts:FunnelChart>

Add a Legend

<Charts:FunnelChart.Legend>
    <Charts:Legend HorizontalPosition="Right"
                   VerticalPosition="Center"
                   Orientation="Vertical"
                   Margin="40,0,0,0"/>
</Charts:FunnelChart.Legend>

Results

The chart is ready. Your code and XAML should look as follows:

<Window
    x:Class="FunnelChartSample.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:FunnelChartSample"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Charts="using:DevExpress.WinUI.Charts"
    mc:Ignorable="d">
    <Grid>
        <Grid.DataContext>
            <local:ChartViewModel/>
        </Grid.DataContext>
        <Charts:FunnelChart>
            <Charts:FunnelChart.Series>
                <Charts:FunnelSeries>
                    <Charts:FunnelSeries.Data>
                        <Charts:DataSource PointSource="{Binding DataPoints}"
                                           ArgumentDataMember="Argument"
                                           ValueDataMember="Value"/>
                    </Charts:FunnelSeries.Data>
                    <Charts:FunnelSeries.View>
                        <Charts:FunnelSeriesView PointDistance="10" 
                                                 ShowLabels="True"
                                                 LabelPattern="{}{A}: {VP:p2}"
                                                 LabelPosition="LeftColumn" 
                                                 Title="Website Visitors"
                                                 LegendPointPattern="{}{A}: {V}">
                            <Charts:FunnelSeriesView.TitleContentTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding}" 
                                               FontSize="18" 
                                               Margin="20"/>
                                </DataTemplate>
                            </Charts:FunnelSeriesView.TitleContentTemplate>
                        </Charts:FunnelSeriesView>
                    </Charts:FunnelSeries.View>
                </Charts:FunnelSeries>
            </Charts:FunnelChart.Series>
            <Charts:FunnelChart.Legend>
                <Charts:Legend HorizontalPosition="Right"
                               VerticalPosition="Center"
                               Orientation="Vertical"
                               Margin="40,0,0,0"/>
            </Charts:FunnelChart.Legend>
        </Charts:FunnelChart>
    </Grid>
</Window>
using DevExpress.Mvvm;
using Microsoft.UI.Xaml;
using System.Collections.Generic;

namespace FunnelChartSample {
    public sealed partial class MainWindow : Window {
        public MainWindow() {
            this.InitializeComponent();
        }
    }
    public class DataPoint {
        public string Argument { get; set; }
        public double Value { get; set; }
    }
    public class ChartViewModel : ViewModelBase {
        public ChartViewModel() {
            List<DataPoint> dataPoints = new List<DataPoint> {
                new DataPoint() { Argument = "Visited a Website",    Value = 9152 },
                new DataPoint() { Argument = "Downloaded a Trial",   Value = 6870 },
                new DataPoint() { Argument = "Contacted to Support", Value = 5121 },
                new DataPoint() { Argument = "Subscribed",           Value = 2224 },
                new DataPoint() { Argument = "Renewed",              Value = 1670 }
            };
            DataPoints = dataPoints;
        }
        public List<DataPoint> DataPoints { get; }
    }
}

Run the project. The following image illustrates the resulting chart:

DevExpress WinUI | Get Started - Funnel Chart