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

Free Support Forum - aspose.com

How to rename chart series as legends via Aspose.Cells in .NET


Please, specify as to how to rename the Series1, Series2 displayed as legend(s) for an chart as shown in the file attachment chart_legend_naming.JPG.

Code to create chart in excel worksheet as follows:

//Adding a chart to the worksheet
int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 5, 6, 30, 19);
Aspose.Cells.Charts.Chart chart1 = worksheet.Charts[chartIndex];
i = 71;
for (int j = 5; j <= 16; j++)
worksheet.Cells["F" + i.ToString()].PutValue(Math.Round((Convert.ToDouble(objRow[j].ToString()) / 1000), 2));
worksheet.Cells["F" + i.ToString()].SetStyle(stlDataCell);
i = 71;
for (int j = 17; j <= 28; j++)
worksheet.Cells["G" + i.ToString()].PutValue(Math.Round((Convert.ToDouble(objRow[j].ToString()) / 1000), 2));
worksheet.Cells["G" + i.ToString()].SetStyle(stlDataCell);
//Setting the title of a chart
chart1.Title.Text = "Title1";
//Setting the font color of the chart title to blue
chart1.Title.TextFont.Color = Color.Black;
chart1.Title.TextFont.IsBold = true;
chart1.PlotArea.Area.ForegroundColor = System.Drawing.Color.FromArgb(196, 224, 196);
//Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3"
chart1.NSeries.Add("F71:G82", true);
//Setting the data source for the category data of SeriesCollection
chart1.NSeries.CategoryData = "H71:H82";

When the .xlsx file gets generated it automatically puts in values as Series1 and Series2 as two different legends.

I would like to rename the legends i.e.., Series1 as Year1 and Series2 as Year2. {As shown in the attached file}

So, please, specify how to do it in c#.net that would allow to change the automatically generated 'Series1' and 'Series2' legend names to some thing else such as 'Year1' and 'Year2' as shown in the picture attached to this post. Did some readings online but couldn't find any solution.




I think you may try to use Series.Name attribute for your requirement, e.g

Series aSeries1 = chart1.NSeries[0];

aSeries1.Name = “Year1”;

Series aSeries2 = chart1.NSeries[1];

aSeries2.Name = “Year2”;

Hi Sahi,

It worked.