Skip to content

Added sample for shapes in chart #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -100,6 +101,9 @@ public static async Task<string> 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
}