/
LegendActions.cs
60 lines (48 loc) · 2.22 KB
/
LegendActions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Drawing;
using System.Globalization;
using DevExpress.Spreadsheet;
using DevExpress.Spreadsheet.Charts;
using DevExpress.Spreadsheet.Drawings;
using DevExpress.Utils;
namespace SpreadsheetChartAPIActions {
public static class LegendActions {
static void HideLegend(IWorkbook workbook) {
#region #HideLegend
Worksheet worksheet = workbook.Worksheets["chartTask3"];
workbook.Worksheets.ActiveWorksheet = worksheet;
// Create a chart and specify its location.
Chart chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet["B2:F6"]);
chart.TopLeftCell = worksheet.Cells["H2"];
chart.BottomRightCell = worksheet.Cells["N14"];
// Hide the legend.
chart.Legend.Visible = false;
#endregion #HideLegend
}
static void SetLegendPosition(IWorkbook workbook) {
#region #SetLegendPosition
Worksheet worksheet = workbook.Worksheets["chartTask3"];
workbook.Worksheets.ActiveWorksheet = worksheet;
// Create a chart and specify its location.
Chart chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet["B2:F6"]);
chart.TopLeftCell = worksheet.Cells["H2"];
chart.BottomRightCell = worksheet.Cells["N14"];
// Specify the position of the legend.
chart.Legend.Position = LegendPosition.Bottom;
#endregion #SetLegendPosition
}
static void ExcludeLegendEntry(IWorkbook workbook) {
#region #ExcludeLegendEntry
Worksheet worksheet = workbook.Worksheets["chartTask3"];
workbook.Worksheets.ActiveWorksheet = worksheet;
// Create a chart and specify its location.
Chart chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet["B2:F6"]);
chart.TopLeftCell = worksheet.Cells["H2"];
chart.BottomRightCell = worksheet.Cells["N14"];
// Exclude entries from the legend.
chart.Legend.CustomEntries.Add(2).Hidden = true;
chart.Legend.CustomEntries.Add(3).Hidden = true;
#endregion #ExcludeLegendEntry
}
}
}