-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new sample for chart legend entries
- Loading branch information
1 parent
c18d1f7
commit ecdd13d
Showing
6 changed files
with
96 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using OfficeOpenXml; | ||
using OfficeOpenXml.Drawing; | ||
using OfficeOpenXml.Drawing.Chart; | ||
using OfficeOpenXml.Drawing.Chart.Style; | ||
using System.Drawing; | ||
using System.Threading.Tasks; | ||
|
||
namespace EPPlusSamples | ||
{ | ||
public class ColumnChartWithLegendSample : ChartSampleBase | ||
{ | ||
public static async Task Add(string connectionString, ExcelPackage package) | ||
{ | ||
var ws = package.Workbook.Worksheets.Add("ColumnCharts"); | ||
|
||
var range = await LoadFromDatabase(connectionString, ws); | ||
|
||
//Add a line chart | ||
var chart = ws.Drawings.AddBarChart("ColumnChartWithLegend", eBarChartType.ColumnStacked); | ||
var serie1 = chart.Series.Add(ws.Cells[2, 2, 16, 2], ws.Cells[2, 1, 16, 1]); | ||
serie1.Header = "Order Value"; | ||
var serie2 = chart.Series.Add(ws.Cells[2, 3, 16, 3], ws.Cells[2, 1, 16, 1]); | ||
serie2.Header = "Tax"; | ||
var serie3 = chart.Series.Add(ws.Cells[2, 4, 16, 4], ws.Cells[2, 1, 16, 1]); | ||
serie3.Header = "Freight"; | ||
chart.SetPosition(0, 0, 6, 0); | ||
chart.SetSize(1200, 400); | ||
chart.Title.Text = "Column chart"; | ||
|
||
//Set style 10 | ||
chart.StyleManager.SetChartStyle(ePresetChartStyle.ColumnChartStyle10); | ||
|
||
chart.Legend.Entries[0].Font.Fill.Color = Color.Red; | ||
chart.Legend.Entries[1].Font.Fill.Color = Color.Green; | ||
chart.Legend.Entries[2].Deleted = true; | ||
|
||
range.AutoFitColumns(0); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters