Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET Excel
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.Legend.Add();
            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());
            pck.Dispose();
 
            Console.WriteLine("Done - Path: {0}", path);
            Console.ReadLine();
 


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.
Posted 10-Jan-13 18:41pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

EPPlus and OfficeOpenXml are two different things, try this page for a charting sample:
http://epplus.codeplex.com/wikipage?title=StatisticsSheetExample[^]
  Permalink  
Comments
Taresh Uppal at 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 at 11-Jan-13 1:22am
   
The above example is pretty clear.
Mika Wendelius at 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 at 11-Jan-13 1:33am
   
Cheers Mika!
 
Congratulations to you too!
 
Plans are gooood! :)
Mika Wendelius at 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)



Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 11 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100