Getting Started with .NET MAUI Pyramid Chart

8 Jul 20268 minutes to read

This section explains how to populate the pyramid chart with data, a title, data labels, a legend, and tooltips, as well as the essential aspects for getting started with the pyramid chart.

To get started quickly with the .NET MAUI Pyramid Chart, you can check the following video.

Prerequisites

Before proceeding, ensure the following are set up:

  1. Install .NET 9 SDK or later.
  2. Set up a .NET MAUI environment with Visual Studio 2022 v17.12 or later.

Step 1: Create a new .NET MAUI project

  1. Go to File > New > Project and choose the .NET MAUI App template.
  2. Name the project and choose a location. Click Next.
  3. Select the .NET framework version and click Create.

Step 2: Install the Syncfusion® MAUI Charts NuGet package

  1. In Solution Explorer, right-click the project and choose Manage NuGet Packages.
  2. Search for Syncfusion.Maui.Charts and install the latest version.
  3. Ensure the necessary dependencies are installed correctly, and the project is restored.

Prerequisites

Before proceeding, ensure the following are set up:

  1. Install .NET 9 SDK or later.
  2. Set up a .NET MAUI environment with Visual Studio Code.
  3. Ensure that the .NET MAUI workloads are installed and configured as described here.

Step 1: Create a new .NET MAUI project

  1. Open the Command Palette by pressing Ctrl+Shift+P, type .NET:New Project, and press Enter.
  2. Choose the .NET MAUI App template.
  3. Select the project location, type the project name, and press Enter.
  4. Then choose Create project.

Step 2: Install the Syncfusion® MAUI Charts NuGet package

  1. Press Ctrl + ` (backtick) to open the integrated terminal in Visual Studio Code.
  2. Ensure you’re in the project root directory where your .csproj file is located.
  3. To ensure all dependencies are installed, run dotnet restore.

Prerequisites

Before proceeding, ensure the following are set up:

  1. Install .NET 9 SDK or later.
  2. Set up a .NET MAUI environment with JetBrains Rider 2024.3 or later.
  3. Make sure the MAUI workloads are installed and configured as described here.

Step 1: Create a new .NET MAUI project

  1. Go to File > New Solution, select .NET (C#), and choose the .NET MAUI App template.
  2. Enter the Project Name, Solution Name, and Location.
  3. Select the .NET framework version and click Create.

Step 2: Install the Syncfusion® MAUI Charts NuGet package

  1. In Solution Explorer, right-click the project and choose Manage NuGet Packages.
  2. Search for Syncfusion.Maui.Charts and install the latest version.
  3. Ensure the necessary dependencies are installed correctly, and the project is restored. If not, open the Terminal in Rider and manually run: dotnet restore

Step 3: Register Syncfusion handler

The Syncfusion handler must be registered to enable all Syncfusion MAUI controls in your application. Add the following namespace to your MauiProgram.cs file:

using Syncfusion.Maui.Core.Hosting;

Register the Syncfusion core handler in your CreateMauiApp method of MauiProgram.cs file:

public static class MauiProgram
{
    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();
        builder
            .UseMauiApp<App>()
            .ConfigureSyncfusionCore()
            .ConfigureFonts(fonts =>
            {
                fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
            });

#if DEBUG
        builder.Logging.AddDebug();
#endif

        return builder.Build();
    }
}

Step 4: Define the data model and view model

First, define a simple data model that represents a data point in the chart:

public class PyramidModel
{
    public string XValue { get; set; }
    public double YValue { get; set; }
}

Next, create a PyramidViewModel class and initialize a list of PyramidModel objects:

public class PyramidViewModel
{
    public List<PyramidModel> Data { get; set; }

    public PyramidViewModel()
    {
        Data = new List<PyramidModel>()
        {
            new PyramidModel() { XValue = "Stage A", YValue = 12 },
            new PyramidModel() { XValue = "Stage B", YValue = 21 },
            new PyramidModel() { XValue = "Stage C", YValue = 29 },
            new PyramidModel() { XValue = "Stage D", YValue = 37 },
        };
    }
}

Create a PyramidViewModel instance and set it as the chart’s BindingContext. This enables property binding from the PyramidViewModel class.

NOTE

Add the namespace of the PyramidViewModel class to your XAML Page if you prefer to set BindingContext in XAML.

Step 5: Import the Pyramid Chart namespace

Add the following namespace in your XAML or C#:

xmlns:chart="clr-namespace:Syncfusion.Maui.Charts;assembly=Syncfusion.Maui.Charts"
using Syncfusion.Maui.Charts;

Step 6: Populate chart with data

Initialize the SfPyramidChart and bind the Data to it by using the ItemsSource property. The data can be provided through the BindingContext, enabling you to create a customized pyramid chart with your own data.

<chart:SfPyramidChart ItemsSource="{Binding Data}" 
                      XBindingPath="XValue" 
                      YBindingPath="YValue"
                      ShowDataLabels="True" 
                      EnableTooltip="True">

    <chart:SfPyramidChart.BindingContext>
        <model:PyramidViewModel/>
    </chart:SfPyramidChart.BindingContext>

    <chart:SfPyramidChart.Title>
        <Label Text="Pyramid Stages"/>
    </chart:SfPyramidChart.Title>

    <chart:SfPyramidChart.Legend>
        <chart:ChartLegend/>
    </chart:SfPyramidChart.Legend>

</chart:SfPyramidChart>
SfPyramidChart chart = new SfPyramidChart()
{
    ItemsSource = new PyramidViewModel().Data,
    XBindingPath = "XValue",
    YBindingPath = "YValue",
    ShowDataLabels = true,
    EnableTooltip = true,
    Title = new Label()
    {
        Text = "Pyramid Stages"
    },
    Legend = new ChartLegend()
};

this.Content = chart;

Pyramid chart in .NET MAUI Pyramid Chart

You can download the Pyramid Charts Getting Started sample from GitHub.