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 Python via .NET allows to format data points of Sunburst Chart and Treemap in Python.

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:

with slides.Presentation() as pres:
    chart = pres.slides[0].shapes.add_chart(charts.ChartType.SUNBURST, 100, 100, 450, 400)

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

IChartDataPointLevelsManagerIChartDataPointLevel 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:

    dataPoints = chart.chart_data.series[0].data_points
    dataPoints[3].data_point_levels[0].label.data_label_format.show_value = 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:

    branch1Label = dataPoints[0].data_point_levels[2].label
    branch1Label.data_label_format.show_category_name = False
    branch1Label.data_label_format.show_series_name = True

    branch1Label.data_label_format.text_format.portion_format.fill_format.fill_type = slides.FillType.SOLID
    branch1Label.data_label_format.text_format.portion_format.fill_format.solid_fill_color.color = draw.Color.yellow

todo:image_alt_text

Set Data Point Branch Color

Change color of “Stem 4” branch:

import aspose.slides.charts as charts
import aspose.slides as slides
import aspose.pydrawing as draw

with slides.Presentation() as pres:
    chart = pres.slides[0].shapes.add_chart(charts.ChartType.SUNBURST, 100, 100, 450, 400)
    dataPoints = chart.chart_data.series[0].data_points

    stem4branch = dataPoints[9].data_point_levels[1]
    
    stem4branch.format.fill.fill_type = slides.FillType.SOLID
    stem4branch.format.fill.solid_fill_color.color = draw.Color.red
      
    pres.save("pres.pptx", slides.export.SaveFormat.PPTX)

todo:image_alt_text