diff --git a/05-Drawings charts and themes/03-Charts and themes/ChartsAndThemesSample.cs b/05-Drawings charts and themes/03-Charts and themes/ChartsAndThemesSample.cs index 5f07d6f..cea42fe 100644 --- a/05-Drawings charts and themes/03-Charts and themes/ChartsAndThemesSample.cs +++ b/05-Drawings charts and themes/03-Charts and themes/ChartsAndThemesSample.cs @@ -25,6 +25,7 @@ Date Author Change using System.IO; using OfficeOpenXml.Drawing.Chart.ChartEx; using EPPlusSamples; +using EPPlusSamples._05_Drawings_charts_and_themes._03_Charts_and_themes; namespace EPPlusSamples.DrawingsChartsAndThemes { @@ -100,6 +101,9 @@ public static async Task RunAsync(FileInfo xlFile, FileInfo themeFile) //Add a stackedColumn chart with custom labels BarColumnChartsWithManualLayout.Add(package); + //Add a chart containing shapes and pictures + ShapesAndPicturesInChartSample.Add(package); + //Save our new workbook in the output directory and we are done! package.SaveAs(xlFile); return xlFile.FullName; diff --git a/05-Drawings charts and themes/03-Charts and themes/ShapesAndPicturesInChartSample.cs b/05-Drawings charts and themes/03-Charts and themes/ShapesAndPicturesInChartSample.cs new file mode 100644 index 0000000..0f1fc0a --- /dev/null +++ b/05-Drawings charts and themes/03-Charts and themes/ShapesAndPicturesInChartSample.cs @@ -0,0 +1,44 @@ +using EPPlusSamples.DrawingsChartsAndThemes; +using OfficeOpenXml; +using OfficeOpenXml.Drawing; +using OfficeOpenXml.Drawing.Chart; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EPPlusSamples._05_Drawings_charts_and_themes._03_Charts_and_themes +{ + public class ShapesAndPicturesInChartSample : ChartSampleBase + { + public static async Task Add(ExcelPackage package) + { + var ws = package.Workbook.Worksheets.Add("Chart Drawings"); + + var fullRange = await LoadFromDatabase(ws); + var range = fullRange.SkipRows(1); + + //Add a line chart + var lineChart = ws.Drawings.AddLineChart("line3dChart", eLineChartType.Line3D); + var lineSerie = lineChart.Series.Add(range.TakeSingleColumn(1), range.TakeSingleColumn(0)); + lineSerie.Header = "Order Value"; + lineChart.SetPosition(21, 0, 6, 0); + lineChart.SetSize(1200, 400); + lineChart.Title.Text = "Line 3D"; + + //Add a shape to the chart. + var circle = lineChart.Drawings.AddShape("Circle", eShapeStyle.Ellipse); + //Position and resize the shape. + circle.SetPosition(144, 258); + circle.SetSize(120); + circle.Fill.Color = Color.Orange; + + //Add a picture to the chart. + var pic = lineChart.Drawings.AddPicture("Logo", FileUtil.GetFileInfo("05-Drawings charts and themes\\01-Shapes and images", "EPPlusLogo.jpg")); + //Position the picture. + pic.SetPosition(200, 200); + } + } +}