SunburstDataMapping Class
An object that allows a Sunburst control to convert data source objects to Sunburst sectors.
Namespace: DevExpress.Xpf.TreeMap
Assembly: DevExpress.Xpf.TreeMap.v24.1.dll
NuGet Package: DevExpress.Wpf.TreeMap
Declaration
Example
This example loads data and creates a Sunburst chart based on a hierarchical data source. To do this, follow steps below:
- Initialize the SunburstControl.DataAdapter property with a SunburstHierarchicalDataAdapter object.
- Specify the DataSource property.
- Populate the SunburstHierarchicalDataAdapter.Mappings collection with
SunburstDataMapping
objects to configure how the Sunburst control should convert hierarchical data to sunburst sectors. The number of mappings is equal to the number of data source types you use in the Sunburst chart. Specify the following properties for each mapping:- SunburstDataMapping.LabelDataMember - Specifies a source of labels.
- SunburstDataMapping.ValueDataMember (Optional for inner rings) - Specifies a source of values.
- SunburstDataMapping.ChildrenDataMember property - Specifies a source of child items.
- SunburstDataMapping.Type property - Specifies the type of objects at the current level.
<dxtm:SunburstControl>
<dxtm:SunburstControl.DataAdapter>
<dxtm:SunburstHierarchicalDataAdapter
x:Name="dataAdapter"
DataSource="{Binding}">
<dxtm:SunburstHierarchicalDataAdapter.Mappings>
<dxtm:SunburstDataMapping
LabelDataMember="CountryName"
ChildrenDataMember="CityInfos"
Type="{x:Type local:CountryInfo}"/>
<dxtm:SunburstDataMapping
LabelDataMember="CityName"
ChildrenDataMember="SaleInfos"
Type="{x:Type local:CityInfo}"/>
<dxtm:SunburstDataMapping
ValueDataMember="Total"
LabelDataMember="Category"
Type="{x:Type local:ProductInfo}"/>
</dxtm:SunburstHierarchicalDataAdapter.Mappings>
</dxtm:SunburstHierarchicalDataAdapter>
</dxtm:SunburstControl.DataAdapter>
</dxtm:SunburstControl>
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:
Inheritance
Object
DispatcherObject
DependencyObject
Freezable
SunburstDataMapping
See Also