Skip to main content
All docs
V24.2

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

SunburstHierarchicalDataAdapter Class

Loads data from sources with hierarchical structure.

Namespace: DevExpress.Xpf.TreeMap

Assembly: DevExpress.Xpf.TreeMap.v24.2.dll

NuGet Package: DevExpress.Wpf.TreeMap

#Declaration

public class SunburstHierarchicalDataAdapter :
    SunburstDataAdapterBase

#Remarks

Follow the steps below to load data from hierarchical data sources to a Sunburst chart:

using System.Collections.Generic;
using System.Windows;

namespace HierarchicalSunburst {
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
            DataContext = CreateInfos();
        }
        List<CountryInfo> CreateInfos() {
            List<CountryInfo> infos = new List<CountryInfo>();
            CountryInfo germanyInfo = new CountryInfo { CountryName = "Germany" };
            CityInfo leipzigInfo = new CityInfo { CityName = "Leipzig" };
            leipzigInfo.SaleInfos.AddRange(new List<ProductInfo> {
                new ProductInfo { Category = "Beverages", Total = 2634.5 },
                new ProductInfo { Category = "Baked Goods", Total = 4523.98 },
                new ProductInfo { Category = "Grains and Cereals", Total = 913.85 },
                new ProductInfo { Category = "Milk and Dairy", Total = 4219.98 },
            });
            CityInfo berlinInfo = new CityInfo { CityName = "Berlin" };
            berlinInfo.SaleInfos.AddRange(new List<ProductInfo> {
                new ProductInfo { Category = "Frozen Foods", Total = 900 }
            });
            germanyInfo.CityInfos.AddRange(new List<CityInfo> { leipzigInfo, berlinInfo });

            CountryInfo spainInfo = new CountryInfo { CountryName = "Spain" };
            CityInfo barcelonaInfo = new CityInfo { CityName = "Barcelona" };
            barcelonaInfo.SaleInfos.AddRange(new List<ProductInfo> {
                new ProductInfo { Category = "Baked Goods", Total = 1239.2 },
                new ProductInfo { Category = "Fruits", Total = 450.41 },
                new ProductInfo { Category = "Milk and Dairy", Total = 692.5 },
            });
            CityInfo madridInfo = new CityInfo { CityName = "Madrid" };
            madridInfo.SaleInfos.AddRange(new List<ProductInfo> {
                new ProductInfo { Category = "Spices", Total = 1010.30 },
                new ProductInfo { Category = "Vegetables", Total = 2078 }
            });
            spainInfo.CityInfos.AddRange(new List<CityInfo> { barcelonaInfo, madridInfo });

            infos.AddRange(new List<CountryInfo> { germanyInfo, spainInfo });

            return infos;
        }
    }
    public class CountryInfo {
        public string CountryName { get; set; }
        public List<CityInfo> CityInfos { get; set; } = new List<CityInfo>();
    }
    public class CityInfo {
        public string CityName { get; set; }
        public List<ProductInfo> SaleInfos { get; set; } = new List<ProductInfo>();
    }
    public class ProductInfo {
        public string Category { get; set; }
        public double Total { get; set; }
    }
}

The image below shows the results:

See Also