Pie Charts


#1

I am trying to implement a Pie Chart. I can get all of the other charts to work, except Pie Charts. I am wondering if I could get some sample code. Perhaps I am missing something in my code. I could only find sample code for a Bar Chart in the sample code.

Thanks
Pam


#2

Dear Pam,

Thanks for your consideration. Please try the fowllowing code:

Excel excel = new Excel();
Worksheet sheet = excel.Worksheets[0];
Cells cells = sheet.Cells;
cells[“A1”].PutValue(1);
cells[“B1”].PutValue(2);
cells[“C1”].PutValue(3);

int chartIndex = sheet.Charts.Add(ChartType.Pie, 3, 3, 8, 6);
Chart chart = sheet.Charts[chartIndex];
chart.NSeries.Add(“a1:c1”, false);

excel.Save(“chart.xls”, SaveType.OpenInExcel, FileFormatType.Default, this.Response);


#3

This worked for me. However, in my example, suppose I have 2 columns of data, where 1 column is the ‘label’ and the 2nd column contains the values for the labels. That is where I am stuck. Currently, I pass in the left,uppermost cell (A1) and the right, bottommost cell (B5).

so I changes this line in your example

chart.NSeries.Add(“a1:c1”, false);

to

chart.NSeries.Add(“a1:b5”, false);

I can’t get it to graph in the pie chart properly.

Thanks for all your help.

Pam


#4

OK, I got this figured out. Thanks for your pointers!

Pam