ChartEx - add a axis title

Hello,


I just tried to add an axis title to an existing chart (I do not need code to add it) using Aspose.Slides for .NET (v 6.0), but with no luck.
The class that I need to use to do this is ChartEx. I cannot update to the latest version of Apose.Slides, at least for now.

Please see the attachment for a visual description - I need to add the vertical & horizontal axis that will say “Axis Title”.

Do you have a piece of code that can help me with this?

Appreciate your help!

Hi Lonel,


Thanks for inquiring Aspose.Slides.

I have observe the requirements shared by you and suggest you to please try using our latest version Aspose.Slides for .NET 14.2.0 on your end.

However, I have also created the sample code w.r.t old legacy API for Aspose.Slides for .NET that will help you further in this regard.


public static void addChartTitle()
{
PresentationEx pres = new PresentationEx();
SlideEx slide = pres.Slides[0];

ChartEx chart = slide.Shapes.AddChart(ChartTypeEx.ClusteredColumn, 100, 100, 400, 300);

chart.ValueAxis.HasTitle = true;
chart.ValueAxis.Title.Text.Text = “Value Title”;
chart.ValueAxis.Title.Text.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.FillType = FillTypeEx.Solid;
chart.ValueAxis.Title.Text.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.SolidFillColor.Color = Color.Red;
chart.ValueAxis.Title.Text.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontHeight = 10;
chart.CategoryAxis.HasTitle = true;
chart.CategoryAxis.Title.Text.Text = “Value Title”;
chart.CategoryAxis.Title.Text.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.FillType = FillTypeEx.Solid;
chart.CategoryAxis.Title.Text.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.SolidFillColor.Color = Color.Red;
chart.CategoryAxis.Title.Text.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontHeight = 10;

pres.Save(“C:\Presentations\ChartTest.pptx”, SaveFormat.Pptx);
}


Please share if I may help you further in this regard.

Many Thanks,

Thank you Mudassir … It worked :slight_smile:


One last thing, how can I rotate the axis title?
Please see the attached image. I nee to rotate the “Axis title” label.

This is the code I was using to add that “Axis title”:

chart.CategoryAxis.HasTitle = true;
chart.CategoryAxis.Title.Text.Text = title;

chart.CategoryAxis.Title.Text.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.FillType = FillTypeEx.Solid;
chart.CategoryAxis.Title.Text.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.SolidFillColor.Color = Color.Black;

chart.CategoryAxis.Title.Text.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontHeight = 12;

Thank you for your help!

P.S. Will do the update as soon as I have a chance

Hi Lonel,

I have observed your requirements for setting the chart axis direction. I like to add that you can set the direction to horizontal, vertical or vertical 270. Please try using the attached sample code to serve the purpose. Please share, if I may help you further in this regard.

public static void addChartTitle()
{
PresentationEx pres = new PresentationEx();
SlideEx slide = pres.Slides[0];

ChartEx chart = slide.Shapes.AddChart(ChartTypeEx.ClusteredColumn, 100, 100, 400, 300);

chart.ValueAxis.HasTitle = true;
chart.ValueAxis.Title.Text.Text = “Value Title”;
chart.ValueAxis.Title.Text.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.FillType = FillTypeEx.Solid;
chart.ValueAxis.Title.Text.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.SolidFillColor.Color = Color.Red;
chart.ValueAxis.Title.Text.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontHeight = 10;
chart.ValueAxis.Title.Text.TextVerticalType = TextVerticalTypeEx.Horizontal;

chart.CategoryAxis.HasTitle = true;
chart.CategoryAxis.Title.Text.Text = “Value Title”;
chart.CategoryAxis.Title.Text.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.FillType = FillTypeEx.Solid;
chart.CategoryAxis.Title.Text.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.SolidFillColor.Color = Color.Red;
chart.CategoryAxis.Title.Text.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontHeight = 10;

chart.CategoryAxis.Title.Text.TextVerticalType = TextVerticalTypeEx.Vertical270;
pres.Save(“D:\Aspose Data\ChartTest.pptx”, SaveFormat.Pptx);
}

Many Thanks,

It worked.


Thank you Mudassir!

Hi Lonel,

That is great that things worked on your end as per expectation. Please share, if I may help you further in this regard.

Many Thanks,