-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathViewOptionsActions.cs
More file actions
273 lines (225 loc) · 11.3 KB
/
ViewOptionsActions.cs
File metadata and controls
273 lines (225 loc) · 11.3 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
using DevExpress.Spreadsheet;
using DevExpress.Spreadsheet.Charts;
using DevExpress.Spreadsheet.Drawings;
using System;
using System.Drawing;
namespace SpreadsheetChartAPIActions
{
public static class ViewOptionsActions
{
public static Action<Workbook> ShowAutomaticMarkersAction = ShowAutomaticMarkers;
public static Action<Workbook> ShowCustomMarkersAction = ShowCustomMarkers;
public static Action<Workbook> SmoothLinesAction = SmoothLines;
public static Action<Workbook> GapWidthAction = GapWidth;
public static Action<Workbook> VaryColorsByPointAction = VaryColorsByPoint;
public static Action<Workbook> ChangeChartAppearanceAction = ChangeChartAppearance;
public static Action<Workbook> ApplyGradientToChartBackgroundAction = ApplyGradientToChartBackground;
public static Action<Workbook> CustomWallsAndFloorAction = CustomWallsAndFloor;
static void ShowAutomaticMarkers(Workbook workbook)
{
#region #ShowAutomaticMarkers
Worksheet worksheet = workbook.Worksheets["chartTask5"];
workbook.Worksheets.ActiveWorksheet = worksheet;
// Create a chart and specify its location.
Chart chart = worksheet.Charts.Add(ChartType.Line, worksheet["B2:C8"]);
chart.TopLeftCell = worksheet.Cells["F2"];
chart.BottomRightCell = worksheet.Cells["L15"];
// Display markers using automatic style.
chart.Series[0].Marker.Symbol = MarkerStyle.Auto;
// Hide the legend.
chart.Legend.Visible = false;
#endregion #ShowAutomaticMarkers
}
static void ShowCustomMarkers(Workbook workbook)
{
#region #ShowCustomMarkers
Worksheet worksheet = workbook.Worksheets["chartTask5"];
workbook.Worksheets.ActiveWorksheet = worksheet;
// Create a chart and specify its location.
Chart chart = worksheet.Charts.Add(ChartType.Line, worksheet["B2:C8"]);
chart.TopLeftCell = worksheet.Cells["F2"];
chart.BottomRightCell = worksheet.Cells["L15"];
// Display markers and specify the marker style.
chart.Series[0].Marker.Symbol = MarkerStyle.Circle;
// Hide the legend.
chart.Legend.Visible = false;
#endregion #ShowCustomMarkers
}
static void SetMarkerSize(Workbook workbook)
{
#region #SetMarkerSize
Worksheet worksheet = workbook.Worksheets["chartTask5"];
workbook.Worksheets.ActiveWorksheet = worksheet;
// Create a chart and specify its location.
Chart chart = worksheet.Charts.Add(ChartType.Line, worksheet["B2:C8"]);
chart.TopLeftCell = worksheet.Cells["F2"];
chart.BottomRightCell = worksheet.Cells["L15"];
// Display markers and specify the marker style and size.
chart.Series[0].Marker.Symbol = MarkerStyle.Circle;
chart.Series[0].Marker.Size = 15;
// Hide the legend.
chart.Legend.Visible = false;
#endregion #SetMarkerSize
}
static void SmoothLines(Workbook workbook)
{
#region #SmoothLines
Worksheet worksheet = workbook.Worksheets["chartTask5"];
workbook.Worksheets.ActiveWorksheet = worksheet;
// Create a chart and specify its location.
Chart chart = worksheet.Charts.Add(ChartType.LineMarker, worksheet["B2:C8"]);
chart.TopLeftCell = worksheet.Cells["F2"];
chart.BottomRightCell = worksheet.Cells["L15"];
// Turn on curve smoothing.
chart.Series[0].Smooth = true;
// Hide the legend.
chart.Legend.Visible = false;
#endregion #SmoothLines
}
static void GapWidth(Workbook workbook)
{
#region #GapWidth
Worksheet worksheet = workbook.Worksheets["chartTask5"];
workbook.Worksheets.ActiveWorksheet = worksheet;
// Create a chart and specify its location.
Chart chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet["B2:C8"]);
chart.TopLeftCell = worksheet.Cells["F2"];
chart.BottomRightCell = worksheet.Cells["L15"];
// Set the gap width between data series.
chart.Views[0].GapWidth = 33;
// Hide the legend.
chart.Legend.Visible = false;
#endregion #GapWidth
}
static void VaryColorsByPoint(Workbook workbook)
{
#region #VaryColorsByPoint
Worksheet worksheet = workbook.Worksheets["chartTask5"];
workbook.Worksheets.ActiveWorksheet = worksheet;
// Create a chart and specify its location.
Chart chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet["B2:C8"]);
chart.TopLeftCell = worksheet.Cells["F2"];
chart.BottomRightCell = worksheet.Cells["L15"];
// Specify that each data point in the series has a different color.
chart.Views[0].VaryColors = true;
// Hide the legend.
chart.Legend.Visible = false;
#endregion #VaryColorsByPoint
}
static void ChangeChartAppearance(Workbook workbook)
{
#region #ChangeChartAppearance
Worksheet worksheet = workbook.Worksheets["chartTask7"];
workbook.Worksheets.ActiveWorksheet = worksheet;
// Create a chart and specify its location.
Chart chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet["B2:C8"]);
chart.TopLeftCell = worksheet.Cells["F2"];
chart.BottomRightCell = worksheet.Cells["N17"];
// Add and format the chart title.
chart.Title.SetValue("Сountries with the largest forest area");
chart.Title.Font.Color = Color.FromArgb(0x34, 0x5E, 0x25);
// Set no fill for the plot area.
chart.PlotArea.Fill.SetNoFill();
// Apply the gradient fill to the chart area.
chart.Fill.SetGradientFill(ShapeGradientType.Linear, Color.FromArgb(0xFD, 0xEA, 0xDA), Color.FromArgb(0x77, 0x93, 0x3C));
ShapeGradientFill gradientFill = chart.Fill.GradientFill;
gradientFill.Stops.Add(0.78f, Color.FromArgb(0xB7, 0xDE, 0xE8));
gradientFill.Angle = 90;
// Set the picture fill for the data series.
chart.Series[0].Fill.SetPictureFill("Pictures\\PictureFill.png");
// Customize the axis appearance.
AxisCollection axisCollection = chart.PrimaryAxes;
foreach (Axis axis in axisCollection)
{
axis.MajorTickMarks = AxisTickMarks.None;
axis.Outline.SetSolidFill(Color.FromArgb(0x34, 0x5E, 0x25));
axis.Outline.Width = 1.25;
}
// Change the scale of the value axis.
Axis valueAxis = axisCollection[1];
valueAxis.Scaling.AutoMax = false;
valueAxis.Scaling.Max = 8000000;
valueAxis.Scaling.AutoMin = false;
valueAxis.Scaling.Min = 0;
// Specify display units for the value axis.
valueAxis.DisplayUnits.UnitType = DisplayUnitType.Thousands;
valueAxis.DisplayUnits.ShowLabel = true;
// Hide the legend.
chart.Legend.Visible = false;
#endregion #ChangeChartAppearance
}
static void ApplyGradientToChartBackground(Workbook workbook)
{
#region #ApplyGradientToChartBackground
Worksheet worksheet = workbook.Worksheets["chartScatter"];
workbook.Worksheets.ActiveWorksheet = worksheet;
// Create a chart and specify its location.
Chart chart = worksheet.Charts.Add(ChartType.ScatterLineMarkers, worksheet["C2:D52"]);
chart.TopLeftCell = worksheet.Cells["F2"];
chart.BottomRightCell = worksheet.Cells["L17"];
// Set the series line color.
chart.Series[0].Outline.SetSolidFill(Color.FromArgb(0xBC, 0xCF, 0x02));
// Specify the data markers.
Marker markerOptions = chart.Series[0].Marker;
markerOptions.Symbol = MarkerStyle.Diamond;
markerOptions.Size = 10;
markerOptions.Fill.SetSolidFill(Color.FromArgb(0xBC, 0xCF, 0x02));
markerOptions.Outline.SetNoFill();
// Set no fill for the plot area.
chart.PlotArea.Fill.SetNoFill();
// Apply the gradient fill to the chart area.
chart.Fill.SetGradientFill(ShapeGradientType.Circle, Color.FromArgb(0xE3, 0x48, 0x03), Color.FromArgb(0x00, 0x32, 0x86));
ShapeGradientFill gradientFill = chart.Fill.GradientFill;
gradientFill.FillRect.Left = 0.5;
gradientFill.FillRect.Right = 0.5;
gradientFill.FillRect.Bottom = 0.5;
gradientFill.FillRect.Top = 0.5;
// Set the X-axis scale.
Axis axisX = chart.PrimaryAxes[0];
axisX.Scaling.AutoMax = false;
axisX.Scaling.AutoMin = false;
axisX.Scaling.Max = 60.0;
axisX.Scaling.Min = -60.0;
axisX.MajorGridlines.Visible = true;
axisX.Visible = false;
// Set the Y-axis scale.
Axis axisY = chart.PrimaryAxes[1];
axisY.Scaling.AutoMax = false;
axisY.Scaling.AutoMin = false;
axisY.Scaling.Max = 50.0;
axisY.Scaling.Min = -50.0;
axisY.MajorUnit = 10.0;
axisY.Visible = false;
// Hide the chart legend.
chart.Legend.Visible = false;
#endregion #ApplyGradientToChartBackground
}
static void CustomWallsAndFloor(Workbook workbook)
{
#region #CustomWallsAndFloor
Worksheet worksheet = workbook.Worksheets["chartTask5"];
workbook.Worksheets.ActiveWorksheet = worksheet;
// Create a chart and specify its location.
Chart chart = worksheet.Charts.Add(ChartType.Column3DClustered, worksheet["B2:C8"]);
chart.TopLeftCell = worksheet.Cells["F2"];
chart.BottomRightCell = worksheet.Cells["L15"];
// Specify that each data point in the series has a different color.
chart.Views[0].VaryColors = true;
// Specify the series outline.
chart.Series[0].Outline.SetSolidFill(Color.AntiqueWhite);
// Hide the legend.
chart.Legend.Visible = false;
// Specify the side wall color.
chart.View3D.SideWall.Fill.SetSolidFill(Color.FromArgb(0xDC, 0xFA, 0xDD));
// Specify the pattern fill for the back wall.
chart.View3D.BackWall.Fill.SetPatternFill(Color.FromArgb(0x9C, 0xFB, 0x9F), Color.WhiteSmoke, DevExpress.Spreadsheet.Drawings.ShapeFillPatternType.DiagonalBrick);
SurfaceOptions floorOptions = chart.View3D.Floor;
// Specify the floor color.
floorOptions.Fill.SetSolidFill(Color.FromArgb(0xFA, 0xDC, 0xF9));
// Specify the floor border.
floorOptions.Outline.SetSolidFill(Color.FromArgb(0xB4, 0x95, 0xDE));
floorOptions.Outline.Width = 1.25;
#endregion #CustomWallsAndFloor
}
}
}