-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAxesActions.vb
More file actions
240 lines (188 loc) · 9.55 KB
/
AxesActions.vb
File metadata and controls
240 lines (188 loc) · 9.55 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
Imports System
Imports System.Drawing
Imports System.Globalization
Imports DevExpress.Spreadsheet
Imports DevExpress.Spreadsheet.Charts
Imports DevExpress.Spreadsheet.Drawings
Imports DevExpress.Utils
Namespace SpreadsheetChartAPISamples
Public NotInheritable Class AxesActions
Private Sub New()
End Sub
Public Shared MinAndMaxValuesAction As Action(Of Workbook) = AddressOf MinAndMaxValues
Public Shared MajorUnitsAction As Action(Of Workbook) = AddressOf MajorUnits
Public Shared MajorAndMinorGridlinesAction As Action(Of Workbook) = AddressOf MajorAndMinorGridlines
Public Shared LabelsNumberFormatAction As Action(Of Workbook) = AddressOf LabelsNumberFormat
Public Shared HideTickMarksAction As Action(Of Workbook) = AddressOf HideTickMarks
Public Shared HideAxisLineAction As Action(Of Workbook) = AddressOf HideAxisLine
Public Shared PositionAction As Action(Of Workbook) = AddressOf Position
Public Shared OrientationAction As Action(Of Workbook) = AddressOf Orientation
Public Shared LogScaleAction As Action(Of Workbook) = AddressOf LogScale
Public Shared DisplayUnitsAction As Action(Of Workbook) = AddressOf DisplayUnits
Private Shared Sub MinAndMaxValues(ByVal workbook As Workbook)
#Region "#MinAndMaxValues"
Dim worksheet As Worksheet = workbook.Worksheets("chartTask3")
workbook.Worksheets.ActiveWorksheet = worksheet
' Create a chart and specify its location.
Dim chart As Chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet("B3:C5"))
chart.TopLeftCell = worksheet.Cells("H2")
chart.BottomRightCell = worksheet.Cells("N14")
' Set the minimum and maximum values for the chart value axis.
Dim axis As Axis = chart.PrimaryAxes(1)
axis.Scaling.AutoMax = False
axis.Scaling.Max = 1
axis.Scaling.AutoMin = False
axis.Scaling.Min = 0
' Hide the legend.
chart.Legend.Visible = False
#End Region ' #MinAndMaxValues
End Sub
Private Shared Sub MajorUnits(ByVal workbook As Workbook)
#Region "#MajorUnits"
Dim worksheet As Worksheet = workbook.Worksheets("chartTask2")
workbook.Worksheets.ActiveWorksheet = worksheet
' Create a chart and specify its location.
Dim chart As Chart = worksheet.Charts.Add(ChartType.BarFullStacked)
chart.TopLeftCell = worksheet.Cells("E3")
chart.BottomRightCell = worksheet.Cells("K14")
' Select chart data.
chart.SelectData(worksheet("B4:C8"), ChartDataDirection.Row)
' Set the major unit of the value axis.
chart.PrimaryAxes(1).MajorUnit = 0.2
' Hide the legend.
chart.Legend.Visible = False
#End Region ' #MajorUnits
End Sub
Private Shared Sub MajorAndMinorGridlines(ByVal workbook As Workbook)
#Region "#MajorAndMinorGridlines"
Dim worksheet As Worksheet = workbook.Worksheets("chartTask5")
workbook.Worksheets.ActiveWorksheet = worksheet
' Create a chart and specify its location.
Dim chart As Chart = worksheet.Charts.Add(ChartType.Line, worksheet("B2:C8"))
chart.TopLeftCell = worksheet.Cells("F2")
chart.BottomRightCell = worksheet.Cells("L15")
' Display the major gridlines of the category axis.
chart.PrimaryAxes(0).MajorGridlines.Visible = True
' Display the minor gridlines of the value axis.
chart.PrimaryAxes(1).MinorGridlines.Visible = True
' Hide the legend.
chart.Legend.Visible = False
#End Region ' #MajorAndMinorGridlines
End Sub
Private Shared Sub LabelsNumberFormat(ByVal workbook As Workbook)
#Region "#LabelsNumberFormat"
Dim worksheet As Worksheet = workbook.Worksheets("chartTask3")
workbook.Worksheets.ActiveWorksheet = worksheet
' Create a chart and specify its location.
Dim chart As Chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet("B3:C5"))
chart.TopLeftCell = worksheet.Cells("H2")
chart.BottomRightCell = worksheet.Cells("N14")
' Format the axis labels.
Dim axis As Axis = chart.PrimaryAxes(1)
axis.NumberFormat.FormatCode = "0%"
axis.NumberFormat.IsSourceLinked = False
' Hide the legend.
chart.Legend.Visible = False
#End Region ' #LabelsNumberFormat
End Sub
Private Shared Sub HideTickMarks(ByVal workbook As Workbook)
#Region "#HideTickMarks"
Dim worksheet As Worksheet = workbook.Worksheets("chartTask3")
workbook.Worksheets.ActiveWorksheet = worksheet
' Create a chart and specify its location.
Dim chart As Chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet("B3:C5"))
chart.TopLeftCell = worksheet.Cells("H2")
chart.BottomRightCell = worksheet.Cells("N14")
' Set the axis tick marks.
Dim axis As Axis = chart.PrimaryAxes(0)
axis.MajorTickMarks = AxisTickMarks.None
axis = chart.PrimaryAxes(1)
axis.MajorTickMarks = AxisTickMarks.None
' Hide the legend.
chart.Legend.Visible = False
#End Region ' #HideTickMarks
End Sub
Private Shared Sub HideAxisLine(ByVal workbook As Workbook)
#Region "#HideAxisLine"
Dim worksheet As Worksheet = workbook.Worksheets("chartTask3")
workbook.Worksheets.ActiveWorksheet = worksheet
' Create a chart and specify its location.
Dim chart As Chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet("B3:C5"))
chart.TopLeftCell = worksheet.Cells("H2")
chart.BottomRightCell = worksheet.Cells("N14")
' Hide the axis line.
chart.PrimaryAxes(1).Outline.SetNoFill()
' Hide the legend.
chart.Legend.Visible = False
#End Region ' #HideAxisLine
End Sub
Private Shared Sub Position(ByVal workbook As Workbook)
#Region "#AxisPosition"
Dim worksheet As Worksheet = workbook.Worksheets("chartTask3")
workbook.Worksheets.ActiveWorksheet = worksheet
' Create a chart and specify its location.
Dim chart As Chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet("B3:C5"))
chart.TopLeftCell = worksheet.Cells("H2")
chart.BottomRightCell = worksheet.Cells("N14")
' Set the positon of the value axis.
chart.PrimaryAxes(1).Position = AxisPosition.Right
' Hide the legend.
chart.Legend.Visible = False
#End Region ' #AxisPosition
End Sub
Private Shared Sub Orientation(ByVal workbook As Workbook)
#Region "#AxisOrientation"
Dim worksheet As Worksheet = workbook.Worksheets("chartTask3")
workbook.Worksheets.ActiveWorksheet = worksheet
' Create a chart and specify its location.
Dim chart As Chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet("B3:C5"))
chart.TopLeftCell = worksheet.Cells("H2")
chart.BottomRightCell = worksheet.Cells("N14")
' Reverse the category axis.
chart.PrimaryAxes(0).Scaling.Orientation = AxisOrientation.MaxMin
' Hide the legend.
chart.Legend.Visible = False
#End Region ' #AxisOrientation
End Sub
Private Shared Sub LogScale(ByVal workbook As Workbook)
#Region "#LogScale"
Dim worksheet As Worksheet = workbook.Worksheets("chartTask5")
workbook.Worksheets.ActiveWorksheet = worksheet
' Create a chart and specify its location.
Dim chart As Chart = worksheet.Charts.Add(ChartType.Line, worksheet("B2:D8"))
chart.TopLeftCell = worksheet.Cells("F2")
chart.BottomRightCell = worksheet.Cells("L15")
' Set the logarithmic(Log10) type of scale.
chart.PrimaryAxes(1).Scaling.LogScale = True
chart.PrimaryAxes(1).Scaling.LogBase = 10
' Set the position of the legend on the chart.
chart.Legend.Position = LegendPosition.Bottom
#End Region ' #LogScale
End Sub
Private Shared Sub DisplayUnits(ByVal workbook As Workbook)
#Region "#DisplayUnits"
Dim worksheet As Worksheet = workbook.Worksheets("chartTask7")
workbook.Worksheets.ActiveWorksheet = worksheet
' Create a chart and specify its location.
Dim chart As Chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet("B2:C8"))
chart.TopLeftCell = worksheet.Cells("F2")
chart.BottomRightCell = worksheet.Cells("N17")
' Change the scale of the value axis.
Dim axisCollection As AxisCollection = chart.PrimaryAxes
Dim valueAxis As Axis = 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
' Set the chart style.
chart.Style = ChartStyle.ColorBevel
chart.Views(0).VaryColors = True
' Hide the legend.
chart.Legend.Visible = False
#End Region ' #DisplayUnits
End Sub
End Class
End Namespace