Free Support Forum - aspose.com

Insert Charts as a new Worksheet

Dear all,

I would like to create a chart using Aspose.Excel. First of all I’m writing the content of the chart into an existing worksheet, provided by a document template. In the second step I would like to create the chart as a new worksheet and insert this new sheet after the data sheet. How can I perform this task? Using Interop I used XlChartLocation.xlLocationAsNewSheet to determine the arrangement of the Chart within the document.

Thanks in advance

Erik

Hi Erik,

To create a chart worksheet, please try:

Excel excel = new Excel();

Worksheet sheet = excel.Worksheets[0];
sheet.Cells["A1"].PutValue(1);
sheet.Cells["A2"].PutValue(2);
sheet.Cells["A3"].PutValue(3);

int sheetIndex = excel.Worksheets.Add(SheetType.Chart);
sheet = excel.Worksheets[sheetIndex];
int index = sheet.Charts.Add(ChartType.Column, 0, 0, 0, 0);
Chart chart = sheet.Charts[index];
chart.NSeries.Add("Sheet1!A1:A3", true);

excel.Save("d:\\test\\abc.xls");

Hi Laurence,

Thanks for your reply. Now I’m able to create the chart. But there is still one question left. How can I create the diagram, if for example column “B” contains the values for the X – Axis and column “C” the values for the Y – Axis? If I use

chart.NSeries.Add("Sheet1!B2:C10",true);

two series are created.

Erik

Hi Erik,

Please check http://www.aspose.com/Wiki/default.aspx/Aspose.Cells/SettingChartsData.html .