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

Free Support Forum - aspose.com

Chart.Titles property not available

Hi. We are using the latest version 4.5.0.0 and according to your online documentation the Chart class should have a Titles property that would enable multi-line titles to be created. However, using the following code there is no Titles property:

Worksheet cws = wb.Worksheets[“NewChart”];
Chart chart = cws.Charts[0];
chart.NSeries.Clear();
chart.Type = ChartType.Column;
chart. <---- when typing this, no Titles property is available.

Can you please confirm if the documentation is wrong or if there is another reason for this?

I know we could use \n for a new line, but we need to specify different formatting for each title line.

Thanks.

Hi;

As per your above mentioned issue, I would like to clear one thing that the chart class you are using belongs to Aspose.Cells API which does not support chart.Titles property. The chart.Titles property which you are referring to in the online documentation belongs to Aspose.Charts API's chart class.

Have a good time.

Hi,

Well, actually Chart class has Title property and not Titles, Where did you find the Titles property in the documentation?

You may set the title of a chart or chart objects (e.g.., Axis objects like ValueAxis, CategoryAxis etc.) in the following way:

chart.Title.Text = "Title";

chart.CategoryAxis.Title.Text = "Category";

chart.ValueAxis.Title.Text = "Value";

I think you can format different lines of a multi-line chart title. May the following sample code help you for your need, kindly consult it:

Sample code:

Workbook workbook = new Workbook();

//Set default font
Style style = workbook.DefaultStyle;
style.Font.Name = "Tahoma";
workbook.DefaultStyle = style;
Worksheet sheet = workbook.Worksheets[0];

//Set the name of worksheet
sheet.Name = "Data";

Cells cells = workbook.Worksheets[0].Cells;

//Put a value into a cell
cells["A1"].PutValue("Region");
cells["A2"].PutValue("France");
cells["A3"].PutValue("Germany");
cells["A4"].PutValue("England");
cells["A5"].PutValue("Sweden");
cells["A6"].PutValue("Italy");
cells["A7"].PutValue("Spain");
cells["A8"].PutValue("Portugal");
cells["B1"].PutValue("Sale");
cells["B2"].PutValue(70000);
cells["B3"].PutValue(55000);
cells["B4"].PutValue(30000);
cells["B5"].PutValue(40000);
cells["B6"].PutValue(35000);
cells["B7"].PutValue(32000);
cells["B8"].PutValue(10000);

int sheetIndex = workbook.Worksheets.Add();
sheet = workbook.Worksheets[sheetIndex];

//Set the name of worksheet
sheet.Name = "Chart";

//Create chart
int chartIndex = 0;
chartIndex = sheet.Charts.Add(ChartType.Pie3DExploded, 1, 1, 25, 10);
Chart chart = sheet.Charts[chartIndex];

//Set properties of chart
chart.PlotArea.Area.ForegroundColor = Color.Coral;
chart.PlotArea.Area.FillFormat.SetTwoColorGradient(Color.Yellow, Color.White, GradientStyleType.Vertical, 2);
chart.PlotArea.Border.IsVisible = false;

//Set properties of chart title
chart.Title.Text = "Testing Chart Title for \nSales By Region";
chart.Title.Characters(24, 16).Font.Color = Color.Blue;
chart.Title.Characters(24, 16).Font.IsBold = true;
chart.Title.Characters(24, 16).Font.Size = 15;
chart.Title.Characters(24, 16).Font.Underline = FontUnderlineType.Single;


//Set properties of nseries
chart.NSeries.Add("Data!B2,Data!B4,Data!B6,Data!B8", true);
chart.NSeries.CategoryData = "Data!A2,Data!A4,Data!A6,Data!A8";
chart.NSeries.IsColorVaried = true;

//Set the ChartArea
ChartArea chartarea = chart.ChartArea;
chartarea.Area.Formatting = FormattingType.Custom;
chartarea.Area.FillFormat.Texture = TextureType.BlueTissuePaper;
//Set the Legend.
Legend legend = chart.Legend;
legend.Position = LegendPositionType.Left;
legend.Height = 100;
legend.Width = 130;
legend.Y = 1500;
legend.TextFont.IsBold = true;
legend.Border.Color = Color.Blue;
legend.Area.Formatting = FormattingType.Custom;
legend.Area.FillFormat.SetTwoColorGradient(Color.Yellow, Color.White, GradientStyleType.Horizontal, 1);
//Save the excel file
workbook.Save("f:\\test\\title_pie_chart.xls");

Thank you.