-
Notifications
You must be signed in to change notification settings - Fork 4
/
AxesActions.vb
199 lines (154 loc) · 6.49 KB
/
AxesActions.vb
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
Imports Microsoft.VisualBasic
Imports System
Imports System.Drawing
Imports System.Globalization
Imports DevExpress.Spreadsheet
Imports DevExpress.Spreadsheet.Charts
Imports DevExpress.Spreadsheet.Drawings
Imports DevExpress.Utils
Namespace SpreadsheetChartAPIActions
Public NotInheritable Class AxesActions
Private Sub New()
End Sub
Private Shared Sub MinAndMaxValues(ByVal workbook As IWorkbook)
' #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 IWorkbook)
' #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 IWorkbook)
' #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 IWorkbook)
' #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 IWorkbook)
' #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 IWorkbook)
' #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 IWorkbook)
' #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 IWorkbook)
' #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 IWorkbook)
' #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
End Class
End Namespace