Click here to Skip to main content
15,791,739 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have installed EPPLus library in my project and I am new to it. I want to create a pie chart from the data entered in the sheet. However I am not able to do so.
Here is my code :
<pre lang="c#">
            ExcelPackage pck = new ExcelPackage();
            pck.Workbook.Properties.Title = "Charts With Excel";
            // pck.Workbook.Properties.Company = "***";
            //pck.Workbook.Properties.Author = "*** Reporting";

            var ws = pck.Workbook.Worksheets.Add("***");
            var cell = ws.Cells["A1"];
            Random r = new Random();
            ws.View.ShowGridLines = false;
            var range = ws.Cells["A"];
            var table = ws.Tables.First();
            int datarows = table.Address.End.Row;

            ws.Cells[1, 1].Value = "";
            ws.Cells[1, 1].Value = "";
            ws.Cells[1, 2].Value = "Student1";
            ws.Cells[1, 3].Value = "Student2";
            ws.Cells[1, 4].Value = "Student3";

            ws.Cells[2, 1].Value = "Term1";
            ws.Cells[2, 2].Value = "80";
            ws.Cells[2, 3].Value = "65";
            ws.Cells[2, 4].Value = "45";

            ws.Cells[3, 1].Value = "Term2";
            ws.Cells[3, 2].Value = "78";
            ws.Cells[3, 3].Value = "72";
            ws.Cells[3, 4].Value = "60";

            ws.Cells[4, 1].Value = "Term3";
            ws.Cells[4, 2].Value = "82";
            ws.Cells[4, 3].Value = "80";
            ws.Cells[4, 4].Value = "65";

            ws.Cells[5, 1].Value = "Term4";
            ws.Cells[5, 2].Value = "75";
            ws.Cells[5, 3].Value = "82";
            ws.Cells[5, 4].Value = "68";
            range = ws.SelectedRange;


            OfficeOpenXml.Drawing.Chart.ExcelPieChart  ec = (OfficeOpenXml.Drawing.Chart.ExcelPieChart)ws.Drawings.AddChart("chart_1", OfficeOpenXml.Drawing.Chart.eChartType.Pie3D);
            ec.SetPosition(1, 0, 3, 0);
            ec.SetSize(500, 200);
            ec.Series.Add("A1", "D5");


           (OfficeOpenXml.Drawing.Chart.ExcelPieChartSerie)ec.Series.Add(ran1, ran2);
            //serie1.Header = ws.Cells["A1"].Value.ToString();

            //ran1 = ws.Cells["B2:B101"];
            //var serie2 = ec.Series.Add(ran1, ran2);
            //serie2.Header = ws.Cells["B1"].Value.ToString();


            string path = @"D:\test1.xlsx";
            File.WriteAllBytes(path, pck.GetAsByteArray());

            Console.WriteLine("Done - Path: {0}", path);

I know m missing smething and I have tried a lot finding from the examples of code plex but I am not sure what's the solution to it. Moreover how to get range in epplus.
Please help me. I shall be highly thankgull to you.

1 solution

EPPlus and OfficeOpenXml are two different things, try this page for a charting sample:[^]
Share this answer
Taresh Uppal 11-Jan-13 0:58am    
I am using this page only for my reference however I am not able to get what's the problem. Means Where I need to actually modify my code so that the data I am entering in my sheet can also be visible in pie chart format ???
Mehdi Gholam 11-Jan-13 1:22am    
The above example is pretty clear.
Wendelius 11-Jan-13 1:25am    
Good link, 5'ed

Few other things, first of all congrats to the MVP status! Also Sandeep noted me that Chris has asked us not to modify spam mails in any way, just report them. I think they have a good plan of applying new kind of filter...
Mehdi Gholam 11-Jan-13 1:33am    
Cheers Mika!

Congratulations to you too!

Plans are gooood! :)
Wendelius 11-Jan-13 1:38am    
Thanks :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900