We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Unable to Change the Font of a Treemap Chart

Hi, I can use the following code to change the font of any chart other than a Treemap chart in a powerpoint slide.

chart.TextFormat.PortionFormat.LatinFont = new FontData("Arial");
chart.TextFormat.PortionFormat.FontHeight = 11;

The version of the Aspose.Slides for .NET I used is 21.9.0. How can I change the font of a Treemap chart?

@admangowilson,
Thank you for the issue description. I reproduced the problem with changing the chart font and logged the issue with ID SLIDESNET-42832 in our tracking system. Our development team will investigate this case. You will be notified when the problem is resolved.

@admangowilson,
Our development team has investigated the issue. Unfortunately, the property Chart.TextFormat is not applicable for the following types: ChartType.Treemap, ChartType.Sunburst, ChartType.Waterfall, ChartType.Histogram, ChartType.Funnel and ChartType.BoxAndWhisker. For these types, the text style can’t be set within a chart.

It is a PowerPoint’s interface feature that you can implement as shown below:

using (Presentation pres = new Presentation())
{
    IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.Treemap, 50, 50, 450, 300);

    SetCommonTextStyle(chart.ChartData.Series[0].Labels.DefaultDataLabelFormat.TextFormat);
    SetCommonTextStyle(chart.Legend.TextFormat);
    SetCommonTextStyle(chart.ChartTitle.TextFormat);

    pres.Save(folderPath + "output.pptx", SaveFormat.Pptx);
}
public static void SetCommonTextStyle(IChartTextFormat textFormat)
{
    textFormat.PortionFormat.LatinFont = new FontData("Arial");
    textFormat.PortionFormat.FontHeight = 14;
    textFormat.PortionFormat.FillFormat.FillType = FillType.Solid;
    textFormat.PortionFormat.FillFormat.SolidFillColor.Color = System.Drawing.Color.Green;
}

More examples:
Create Chart
Chart Formatting

I have tried your code, it cannot change the font of the title. I am using the latest Aspose.Slides version 22.1.0.0.

The following is my testing code, it just create a simple tree map chart and add a title then format the font.

static void Main(string[] args)
{
	Aspose.Slides.License license = new Aspose.Slides.License();
	license.SetLicense("Aspose.Slides.NET.lic");

	using (Presentation pres = new Presentation())
	{
		IChart chart = pres.Slides[0].Shapes.AddChart(Aspose.Slides.Charts.ChartType.Treemap, 50, 50, 450, 300);

		chart.ChartTitle.AddTextFrameForOverriding("This is the title");
		chart.ChartTitle.Overlay = false;
		chart.HasTitle = true;

		SetCommonTextStyle(chart.ChartData.Series[0].Labels.DefaultDataLabelFormat.TextFormat);
		SetCommonTextStyle(chart.Legend.TextFormat);
		SetCommonTextStyle(chart.ChartTitle.TextFormat);

		pres.Save("Result.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
	}

}

public static void SetCommonTextStyle(IChartTextFormat textFormat)
    {
        textFormat.PortionFormat.LatinFont = new FontData("Arial");
        textFormat.PortionFormat.FontHeight = 8;
        textFormat.PortionFormat.FillFormat.FillType = FillType.Solid;
        textFormat.PortionFormat.FillFormat.SolidFillColor.Color = System.Drawing.Color.Green;
    }

@admangowilson,
Thank you for reporting the issue.

I’ve reproduced the problem with formatting the chart title and added a ticket with ID SLIDESNET-43051 in our issue tracking system. We apologize for any inconvenience. Our development team will investigate this case. You will be notified when the issue is resolved.