Getting Started with .NET MAUI Sunburst Chart

9 Jul 20269 minutes to read

This section explains how to populate the sunburst chart with data, a title, data labels, a legend, and a tooltip, as well as the essential aspects of getting started with the Sunburst Chart.

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® .NET MAUI Sunburst Chart package

  1. In Solution Explorer, right-click the project and choose Manage NuGet Packages.
  2. Search for Syncfusion.Maui.SunburstChart 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® .NET MAUI Sunburst Chart 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. Run the command dotnet add package Syncfusion.Maui.SunburstChart to install the Syncfusion® .NET MAUI SunburstChart NuGet package.
  4. 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® .NET MAUI Sunburst Chart package

  1. In Solution Explorer, right-click the project and choose Manage NuGet Packages.
  2. Search for Syncfusion.Maui.SunburstChart 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 the Syncfusion handler

The Syncfusion handler registration initializes the platform renderers required for Syncfusion controls to render on Android, iOS, macOS, and Windows. Register the Syncfusion core handler in the CreateMauiApp method of the MauiProgram.cs file.

using Syncfusion.Maui.Core.Hosting;

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();
    }
}

NOTE

The ConfigureSyncfusionCore() call registers all Syncfusion controls, including SfSunburstChart. No separate Sunburst-specific registration is required.

Step 4: Create the Model and ViewModel

Now, let us define a simple data Model and ViewModel that represents a data point in the sunburst chart.

public class SunburstModel
{
    public string Country { get; set; }
    public string JobDescription { get; set; }
    public string JobGroup { get; set; }
    public double EmployeesCount { get; set; }

    public SunburstModel(string country, string jobDescription, string jobGroup, double employeesCount)
    {
        Country = country;
        JobDescription = jobDescription;
        JobGroup = jobGroup;
        EmployeesCount = employeesCount;
    }
}

public class SunburstViewModel
{
    public ObservableCollection<SunburstModel> DataSource { get; set; }

    public SunburstViewModel()
    {
        this.DataSource = new ObservableCollection<SunburstModel>
        {
            new SunburstModel("USA", "Sales", "Executive", 50),
            new SunburstModel("USA", "Sales", "Analyst", 40),
            new SunburstModel("India", "Technical", "Testers", 33),
            new SunburstModel("India", "Technical", "Developers", 125),
            new SunburstModel("Germany", "Sales", "Executive", 30),
            new SunburstModel("Germany", "Sales", "Analyst", 40),
        };
    }
}

Set the SunburstViewModel instance as the BindingContext of your page to bind the SunburstViewModel properties to the chart.

NOTE

Add the namespace of the SunburstViewModel class to your XAML page, if you prefer to set BindingContext in XAML.

Step 5: Import the Sunburst Chart namespace

Add the following namespaces to your XAML or C#.

xmlns:sunburst="clr-namespace:Syncfusion.Maui.SunburstChart;assembly=Syncfusion.Maui.SunburstChart"
using Syncfusion.Maui.SunburstChart;

Step 6: Add the Sunburst Chart component

Initialize the SfSunburstChart control and bind DataSource to the chart’s ItemsSource property from its BindingContext. Then, add SunburstHierarchicalLevel entries to the Levels collection. Each hierarchy level is formed based on the property specified in the GroupMemberPath property, and each arc segment size is calculated using the ValueMemberPath property.

The sample also sets the chart Title, enables the Legend via a SunburstLegend, enables data labels via ShowLabels, and enables tooltips via EnableTooltip.

<sunburst:SfSunburstChart ItemsSource="{Binding DataSource}" 
                          ShowLabels="True"
                          EnableTooltip="True"
                          ValueMemberPath="EmployeesCount">
    <sunburst:SfSunburstChart.BindingContext>
        <model:SunburstViewModel/>
    </sunburst:SfSunburstChart.BindingContext>
    <sunburst:SfSunburstChart.Title>
        <Label Text="Employees Count"/>
    </sunburst:SfSunburstChart.Title>
    <sunburst:SfSunburstChart.Legend>
        <sunburst:SunburstLegend/>
    </sunburst:SfSunburstChart.Legend>
    <sunburst:SfSunburstChart.Levels>
        <sunburst:SunburstHierarchicalLevel GroupMemberPath="Country"/>
        <sunburst:SunburstHierarchicalLevel GroupMemberPath="JobDescription"/>
        <sunburst:SunburstHierarchicalLevel GroupMemberPath="JobGroup"/>
    </sunburst:SfSunburstChart.Levels>
</sunburst:SfSunburstChart>
SfSunburstChart sunburst = new SfSunburstChart();
sunburst.BindingContext = new SunburstViewModel();
sunburst.SetBinding(SfSunburstChart.ItemsSourceProperty, "DataSource");
sunburst.ValueMemberPath = "EmployeesCount";
sunburst.Title = new Label
{
    Text = "Employees Count"
};

sunburst.Legend = new SunburstLegend();
sunburst.Levels.Add(new SunburstHierarchicalLevel() { GroupMemberPath = "Country" });
sunburst.Levels.Add(new SunburstHierarchicalLevel() { GroupMemberPath = "JobDescription" });
sunburst.Levels.Add(new SunburstHierarchicalLevel() { GroupMemberPath = "JobGroup" });
sunburst.EnableTooltip = true;
sunburst.ShowLabels = true;

this.Content = sunburst;

Getting started sample in MAUI Sunburst Chart.

You can download the Sunburst Chart Getting Started sample from GitHub.