Stacked Column chart with legend

Hi, I have created a chart with following sample information. 
Every column is being represented by month-year (eg. Mar-2012, Mar-2013...). ok?
And I want that country name (eg, America, Bahama) should come as legend.
How can I do that?

For your kind information, I have attached the excel document with data and
expected chart which I want. Please help me immediately....

Thanks in advance.

//Sample codes here

Workbook workbook = new Workbook();

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

worksheet.Cells[“A1”].PutValue(“Population Chart”);
worksheet.Cells[“A2”].PutValue(“America”);
worksheet.Cells[“A3”].PutValue(“Bahama”);

worksheet.Cells[“B1”].PutValue(“Mar-2012”);
worksheet.Cells[“B2”].PutValue(10000);

worksheet.Cells[“B3”].PutValue(15000);

worksheet.Cells[“C1”].PutValue(“Mar-2013”);
worksheet.Cells[“C2”].PutValue(12000);
worksheet.Cells[“C3”].PutValue(16000);

worksheet.Cells[“D1”].PutValue(“Mar-2014”);
worksheet.Cells[“D2”].PutValue(14000);
worksheet.Cells[“D3”].PutValue(17000);


chart.NSeries.Add(“B2:D3” false);
chart.NSeries.CategoryData = “B1:D1”;


Hi,


Thanks for query and providing some details.

I have written the sample code for your needs for your reference, please refer to it:
e.g
Sample code:

Workbook workbook = new Workbook();
int sheetIndex = workbook.Worksheets.Add();
Worksheet worksheet = workbook.Worksheets[sheetIndex];
worksheet.Cells[“A1”].PutValue(“Population Chart”);
worksheet.Cells[“A2”].PutValue(“America”);
worksheet.Cells[“A3”].PutValue(“Bahama”);

worksheet.Cells[“B1”].PutValue(“Mar-2012”);
worksheet.Cells[“B2”].PutValue(10000);
worksheet.Cells[“B3”].PutValue(15000);

worksheet.Cells[“C1”].PutValue(“Mar-2013”);
worksheet.Cells[“C2”].PutValue(12000);
worksheet.Cells[“C3”].PutValue(16000);

worksheet.Cells[“D1”].PutValue(“Mar-2014”);
worksheet.Cells[“D2”].PutValue(14000);
worksheet.Cells[“D3”].PutValue(17000);

Chart chart = worksheet.Charts[worksheet.Charts.Add(ChartType.ColumnStacked, 9, 9, 24, 17)];

chart.NSeries.Add(“B2:D3”, false);
chart.NSeries.CategoryData = “B1:D1”;

//Set the Series for legend.
SeriesCollection nseries = chart.NSeries;
for (int i = 0; i < nseries.Count; i++)
{
nseries[i].Name = worksheet.Cells[i + 1, 0].Value.ToString();

}

workbook.Save(“e:\test2\out1.xlsx”);


Hope, this helps a bit.

Thank you.

Hurray, it works fine. Thank you very much.

Hi,


Good to know that it figures out your issue now. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

Thank you.