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

Free Support Forum - aspose.com

Chart.Titel.Text

Hi,

I’ve a problem to get the titel of a chart.

I use

Excel excel = new Excel();

excel.Open(“Test.xls”);

Chart chart = excel.Worksheets[0].DesignCharts[0];

Console.WriteLine(“Titel = {0}”, chart.Titel.Text);

but the console shows

Titel =

What’s wrong?


Andreas

Hi Andreas,

Could you please post your template file here?

Hi Laurence,

I’ve attached the excel-file.


Andreas

Aspose.Excel doesn’t fully support to retrieve data from design charts. I added the feature to retrieve title text in this attached fix.

@uniserv,
Aspose.Cells has replaced Aspose.Excel that is no more available now. With this new product Aspose.Cells, you can configure the charts in a variety of ways including the setting and formatting of the chart title text. Here is an example that can be used to demonstrate this feature.

Workbook wb = new Workbook();
wb.Worksheets.Clear();
Worksheet ws = wb.Worksheets.Add("New");
Style style = wb.CreateStyle();
style.Name = "DateTimeStyle";
style.Custom = "yyyy-mm-dd hh:mm";
DateTime dt = DateTime.Now.Date;
ws.Cells[23, 2].PutValue(dt);
ws.Cells[23, 2].SetStyle(style);
ws.Cells[24, 2].PutValue(dt.AddDays(12));
ws.Cells[24, 2].SetStyle(style);
ws.Cells[25, 2].PutValue(dt.AddDays(24));
ws.Cells[25, 2].SetStyle(style);
ws.Cells[26, 2].PutValue(dt.AddDays(36));
ws.Cells[26, 2].SetStyle(style);
ws.Cells[27, 2].PutValue(dt.AddDays(48));
ws.Cells[27, 2].SetStyle(style);
ws.Cells[28, 2].PutValue(dt.AddDays(60));
ws.Cells[28, 2].SetStyle(style);
ws.Cells[29, 2].PutValue(dt.AddDays(72));
ws.Cells[29, 2].SetStyle(style);
ws.Cells[23, 3].PutValue(3);
ws.Cells[24, 3].PutValue(4);
ws.Cells[25, 3].PutValue(9);
ws.Cells[26, 3].PutValue(13);
ws.Cells[27, 3].PutValue(16);
ws.Cells[28, 3].PutValue(3);
ws.Cells[29, 3].PutValue(7);

Chart chart = ws.Charts[ws.Charts.Add(ChartType.ScatterConnectedByLinesWithoutDataMarker, 1, 1, 22, 12)];
chart.CategoryAxis.TickLabels.NumberFormat = "dd - MMM - yyyy";
chart.CategoryAxis.TickLabels.RotationAngle = 45;
chart.CategoryAxis.TickLabels.Font.Size = 8;
chart.CategoryAxis.TickLabelPosition = TickLabelPositionType.Low;
chart.CategoryAxis.MinValue = new DateTime(2021, 1, 1, 0, 0, 0);
chart.CategoryAxis.MaxValue = new DateTime(2021, 12, 31, 23, 59, 59);
chart.Legend.Position = LegendPositionType.Bottom;
chart.ValueAxis.TickLabels.NumberFormat = "0";
chart.ValueAxis.MinValue = 0;
chart.ValueAxis.MaxValue = 20;
chart.Placement = PlacementType.Move;
String chartSubTitle = DateTime.Now.ToString();
chart.Title.Text = "Data" + "\n" + chartSubTitle;
chart.Title.Font.Color = Color.Red;
Series aSerie = chart.NSeries[chart.NSeries.Add(String.Format("{0}!{1}{2}:{1}{3}", ws.Name, "D", 24, 30), true)];
aSerie.XValues = String.Format("{0}!{1}{2}:{1}{3}", ws.Name, "C", 24, 30);
aSerie.Name = "Date";
aSerie.DropLines.Color = Color.BlanchedAlmond;
aSerie.DropLines.Weight = WeightType.HairLine;
ws.AutoFitColumns();
wb.Save(@"outResult1.xlsx", SaveFormat.Xlsx);

Here is the program output with a formatted chart title.

The following document contains a detailed description of this feature:
Setting Chart Appearance

A free latest trial version of this product is available here:
Aspose.Cells for .NET (Latest Version)

You can test all the features of this product by downloading a runnable solution here.