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";
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);
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.