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 C++ 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:

todo:image_alt_text

Let’s start with adding a new Sunburst chart to the presentation:

auto pres = System::MakeObject<Presentation>();
auto chart = pres->get_Slides()->idx_get(0)->get_Shapes()->AddChart(ChartType::Sunburst, 100.0f, 100.0f, 450.0f, 400.0f);
// ...

If there is a need to format data points of the chart, we should use the following:

IChartDataPointLevelsManagerIChartDataPointLevel classes  and IChartDataPoint::get_DataPointLevels() method  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 methods: get_Format() and  get_Label() which provide access to corresponding settings.

Show Data Point Value

Show value of “Leaf 4” data point:

auto dataPoints = chart->get_ChartData()->get_Series()->idx_get(0)->get_DataPoints();
dataPoints->idx_get(3)->get_DataPointLevels()->idx_get(0)->get_Label()->get_DataLabelFormat()->set_ShowValue(true);

todo:image_alt_text

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:

auto branch1Label = dataPoints->idx_get(0)->get_DataPointLevels()->idx_get(2)->get_Label();
branch1Label->get_DataLabelFormat()->set_ShowCategoryName(false);
branch1Label->get_DataLabelFormat()->set_ShowSeriesName(true);

branch1Label->get_DataLabelFormat()->get_TextFormat()->get_PortionFormat()->get_FillFormat()->set_FillType(FillType::Solid);
branch1Label->get_DataLabelFormat()->get_TextFormat()->get_PortionFormat()->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Yellow());

todo:image_alt_text

Set Data Point Branch Color

Change color of “Stem 4” branch:

auto pres = System::MakeObject<Presentation>();
auto chart = pres->get_Slides()->idx_get(0)->get_Shapes()->AddChart(ChartType::Sunburst, 100.0f, 100.0f, 450.0f, 400.0f);
auto dataPoints = chart->get_ChartData()->get_Series()->idx_get(0)->get_DataPoints();

auto stem4branch = dataPoints->idx_get(9)->get_DataPointLevels()->idx_get(1);
stem4branch->get_Format()->get_Fill()->set_FillType(FillType::Solid);
stem4branch->get_Format()->get_Fill()->get_SolidFillColor()->set_Color(Color::get_Red());

pres->Save(u"pres.pptx", SaveFormat::Pptx);

todo:image_alt_text