Chart created as a new sheet


#1

I would like to create a new chart as a sheet (similar to Excel’s chart wizard option “As Sheet”).

Charts charts = excel.Worksheets[excel.Worksheets.Add(SheetType.Worksheet)].Charts;
int chartIndex = charts.Add(ChartType.ScatterConnectedByLinesWithDataMarker, 0, 0, 40, 20);
Chart oChart = charts[chartIndex];

This uses coordinates for the four corners but I want the chart to fill the page as a complete sheet.

How would I do this?

#2

I am asking the same as this posting:
Re: Putting a chart on a new chart worksheet
http://www.aspose.com/Forums/ShowPost.aspx?PostID=5852


#3

This feature is supported. Please download the latest version and try the following sample code:

Excel excel = new Excel();

excel.Worksheets.Add(SheetType.Chart);

Cells cells = excel.Worksheets[0].Cells;
cells["c2"].PutValue(5000);
cells["c3"].PutValue(3000);
cells["c4"].PutValue(4000);
cells["c5"].PutValue(5000);
cells["c6"].PutValue(6000);



Charts charts = excel.Worksheets[1].Charts;


int chartIndex = charts.Add(ChartType.Column, 10,10,20,20);
Chart chart = charts[chartIndex];
chart.NSeries.Add("Sheet1!C2:C6", true);


#4

I ran this code:
Excel excel = new Excel();
excel.Worksheets.Add(SheetType.Chart);
Cells cells = excel.Worksheets[0].Cells;
cells[“c2”].PutValue(5000);
cells[“c3”].PutValue(3000);
cells[“c4”].PutValue(4000);
cells[“c5”].PutValue(5000);
cells[“c6”].PutValue(6000);
Charts charts = excel.Worksheets[0].Charts;
int chartIndex = charts.Add(ChartType.Column, 10,10,20,20);
Chart chart = charts[chartIndex];
chart.NSeries.Add(“C2:C6”, true);
excel.Save(“book1.xls”, SaveType.OpenInBrowser, FileFormatType.Default, this.Response);

I got an exception, "Object reference not set to an instance of an object."
If I change chart type from Chart to Worksheet, everything works fine.

I have version 3.2.2.7 which fixed XValues property for all XYscatter type charts, thank you!


#5

I got the exception because I was using data entered into the same sheet so please ignore my previous posting as it works okay for chart type.
thank you!


#6

When you create a new chart sheet, you should put chart setting in it.

My code is to add a new chart sheet, while your code is to add a chart in a normal worksheet. Please try my sample code.

If you want to add a chart in a normal worksheet, please remove this line of code:

excel.Worksheets.Add(SheetType.Chart);