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

Free Support Forum - aspose.com

Create two charts in same Excel worksheet in .NET

Hi,

Is it possible to create two charts in same excel sheet ?. If yes, pls send me the code …


thanks in advance,

Hi,


You may create as many charts in a single worksheet, see a simple code for reference:

Sample code:
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
//Put data
sheet.Cells[0, 0].PutValue(“BarCol 1”);
sheet.Cells[0, 1].PutValue(5);
sheet.Cells[0, 2].PutValue(10);
sheet.Cells[0, 3].PutValue(6);
sheet.Cells[0, 4].PutValue(4);
sheet.Cells[0, 5].PutValue(8);
sheet.Cells[1, 0].PutValue(“BarCol 2”);
sheet.Cells[1, 1].PutValue(7);
sheet.Cells[1, 2].PutValue(4);
sheet.Cells[1, 3].PutValue(8);
sheet.Cells[1, 4].PutValue(3);
sheet.Cells[1, 5].PutValue(2);



//Generate the first chart
int chartIndex = sheet.Charts.Add(Aspose.Cells.Charts.ChartType.BarStacked, 2, 0, 20, 7);
Chart chart = sheet.Charts[chartIndex];

//Insert series
chart.NSeries.Add(“B1:F1”, false);
chart.NSeries.Add(“B2:F2”, false);
chart.NSeries.CategoryData = “A1:A2”;

chart.ShowLegend = false;

chart.PlotArea.X = 0;
chart.PlotArea.Y = 0;
chart.PlotArea.Width = 3300;



//Generate the second chart
chartIndex = sheet.Charts.Add(Aspose.Cells.Charts.ChartType.Column3DClustered, 21, 0, 39, 10);
chart = sheet.Charts[chartIndex];

//Insert series
chart.NSeries.Add(“B1:F1”, false);
chart.NSeries.Add(“B2:F2”, false);
chart.NSeries.CategoryData = “A1:A2”;

chart.ShowLegend = false;

chart.PlotArea.X = 0;
chart.PlotArea.Y = 0;
chart.PlotArea.Width = 3300;

workbook.Save(@“e:\test2\2ChartsResultByAspose2.xlsx”);


Thank you.