-
StackOverflow 文件
-
epplus 教程
-
建立圖表
-
餅形圖
//create a new ExcelPackage
using (ExcelPackage excelPackage = new ExcelPackage())
{
//create a WorkSheet
ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets.Add("Sheet 1");
//fill cell data with a loop, note that row and column indexes start at 1
Random rnd = new Random();
for (int i = 1; i <= 10; i++)
{
worksheet.Cells[1, i].Value = "Value " + i;
worksheet.Cells[2, i].Value = rnd.Next(5, 15);
}
//create a new piechart of type Pie3D
ExcelPieChart pieChart = worksheet.Drawings.AddChart("pieChart", eChartType.Pie3D) as ExcelPieChart;
//set the title
pieChart.Title.Text = "PieChart Example";
//select the ranges for the pie. First the values, then the header range
pieChart.Series.Add(ExcelRange.GetAddress(2, 1, 2, 10), ExcelRange.GetAddress(1, 1, 1, 10));
//position of the legend
pieChart.Legend.Position = eLegendPosition.Bottom;
//show the percentages in the pie
pieChart.DataLabel.ShowPercent = true;
//size of the chart
pieChart.SetSize(500, 400);
//add the chart at cell C5
pieChart.SetPosition(4, 0, 2, 0);
}