Free Support Forum - aspose.com

Formatting chart title using ParagraphEx

Hi

I am trying to create title and subtitle in one chart title placeholder. To do this I wrote following code:

private void PutTitleToChart(ChartEx chart)
{
chart.HasTitle = true;

var par = chart.ChartTitle.Text.Paragraphs;
par.Add(new ParagraphEx());
par.Add(new ParagraphEx());

par[0].Text = “Title”;
par[1].Text = “Subtitle”;

par[0].ParagraphFormat.DefaultPortionFormat.FontHeight = 20;
par[0].ParagraphFormat.DefaultPortionFormat.FontItalic = NullableBool.True;
par[1].ParagraphFormat.DefaultPortionFormat.FontHeight = 16;
par[1].ParagraphFormat.DefaultPortionFormat.FontBold = NullableBool.True;
}

Unfortunately in generated chart title has applied only formatting form paragraph 0 and skip formatting paragraph 1. In attachment I sent generated chart which shows the problem.
Is this a bug or I have some wrong in my code?

Thanks
Chris

Hi Chris,


I have observed the code snippet shared by you and like to share that you are setting text on paragraph level by using default portion format setting. In order to retain the font related settings one need to set the text of portion level. Please use the following code snippet to serve the purpose. For your convenience, I have also shared the generated presentation.

private static void PutTitleToChart(ChartEx chart)
{
chart.HasTitle = true;

var par = chart.ChartTitle.Text.Paragraphs;
par.Add(new ParagraphEx());
par.Add(new ParagraphEx());
PortionEx por0 = new PortionEx();
PortionEx por1 = new PortionEx();

por0.PortionFormat.FontHeight = 20;
por0.PortionFormat.FontItalic = NullableBool.True;
por1.PortionFormat.FontHeight = 16;
por1.PortionFormat.FontBold = NullableBool.True;
por1.PortionFormat.FillFormat.FillType = FillTypeEx.Solid;
por1.PortionFormat.FillFormat.SolidFillColor.Color = Color.Red;
por0.Text = “Title”;
por1.Text = “Subtitle”;

par[0].Portions.Add(por0);
par[1].Portions.Add(por1);


}


Many Thanks,

Hi Mudassir,

This is exactly what I need :slight_smile:

Many thanks
Chris