Data Points of Treemap and Sunburst Chart
Among other types of PowerPoint charts, there are two “hierarchical” types - Treemap and Sunburst chart (also known as Sunburst Graph, Sunburst Diagram, Radial Chart, Radial Graph or Multi Level Pie Chart). These charts display hierarchical data organized as a tree - from leaves to the top of the branch. Leaves are defined by the series data points, and each subsequent nested grouping level defined by the corresponding category. Aspose.Slides for .NET allows to format data points of Sunburst Chart and Treemap in C#.
Here is a Sunburst Chart, where data in Series1 column define the leaf nodes, while other columns define hierarchical datapoints:
Let’s start with adding a new Sunburst chart to the presentation:
using (Presentation pres = new Presentation())
{
IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.Sunburst, 100, 100, 450, 400);
// ...
}
See also
If there is a need to format data points of the chart, we should use the following:
IChartDataPointLevelsManager, IChartDataPointLevel classes and IChartDataPoint.DataPointLevels property provide access to format data points of Treemap and Sunburst charts. IChartDataPointLevelsManager is used for accessing multi-level categories - it represents the container of IChartDataPointLevel objects. Basically it is a wrapper for IChartCategoryLevelsManager with the properties added specific for data points. IChartDataPointLevel class has two properties: Format and DataLabel which provide access to corresponding settings.
Show Data Point Value
Show value of “Leaf 4” data point:
IChartDataPointCollection dataPoints = chart.ChartData.Series[0].DataPoints;
dataPoints[3].DataPointLevels[0].Label.DataLabelFormat.ShowValue = true;
Set Data Point Label and Color
Set “Branch 1” data label to show series name (“Series1”) instead of category name. Then set text color to yellow:
IDataLabel branch1Label = dataPoints[0].DataPointLevels[2].Label;
branch1Label.DataLabelFormat.ShowCategoryName = false;
branch1Label.DataLabelFormat.ShowSeriesName = true;
branch1Label.DataLabelFormat.TextFormat.PortionFormat.FillFormat.FillType = FillType.Solid;
branch1Label.DataLabelFormat.TextFormat.PortionFormat.FillFormat.SolidFillColor.Color = Color.Yellow;
Set Data Point Branch Color
Change color of “Stem 4” branch:
using (Presentation pres = new Presentation())
{
IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.Sunburst, 100, 100, 450, 400);
IChartDataPointCollection dataPoints = chart.ChartData.Series[0].DataPoints;
IChartDataPointLevel stem4branch = dataPoints[9].DataPointLevels[1];
stem4branch.Format.Fill.FillType = FillType.Solid;
stem4branch.Format.Fill.SolidFillColor.Color = Color.Red;
pres.Save("pres.pptx", SaveFormat.Pptx);
}