-
Notifications
You must be signed in to change notification settings - Fork 3
/
CreationAndDataActions.vb
125 lines (98 loc) · 5.7 KB
/
CreationAndDataActions.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
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 CreationAndDataActions
Private Sub New()
End Sub
Private Shared Sub CreateChartFromRange(ByVal workbook As Workbook)
' #Region "#CreateChartFromRange"
Dim worksheet As Worksheet = workbook.Worksheets("chartTask1")
workbook.Worksheets.ActiveWorksheet = worksheet
' Create a pie chart and specify its location.
Dim chart As Chart = worksheet.Charts.Add(ChartType.Pie3D, worksheet("B2:C7"))
chart.TopLeftCell = worksheet.Cells("E2")
chart.BottomRightCell = worksheet.Cells("K15")
' Set the chart style.
chart.Style = ChartStyle.ColorGradient
' #End Region ' #CreateChartFromRange
End Sub
Private Shared Sub CreateChartAndSelectData(ByVal workbook As Workbook)
' #Region "#CreateChartAndSelectData"
Dim worksheet As Worksheet = workbook.Worksheets("chartTask2")
workbook.Worksheets.ActiveWorksheet = worksheet
' Create a chart and specify its location.
Dim chartRowData As Chart = worksheet.Charts.Add(ChartType.ColumnStacked)
chartRowData.TopLeftCell = worksheet.Cells("E3")
chartRowData.BottomRightCell = worksheet.Cells("J12")
' Select chart data.
chartRowData.SelectData(worksheet("B3:C8"))
' #End Region ' #CreateChartAndSelectData
End Sub
Private Shared Sub CreateChartAndSelectDataDirection(ByVal workbook As Workbook)
' #Region "#CreateChartAndSelectDataDirection"
Dim worksheet As Worksheet = workbook.Worksheets("chartTask3")
workbook.Worksheets.ActiveWorksheet = worksheet
' Create a chart and specify its location.
Dim chartRowData As Chart = worksheet.Charts.Add(ChartType.ColumnClustered)
chartRowData.TopLeftCell = worksheet.Cells("D3")
chartRowData.BottomRightCell = worksheet.Cells("I14")
' Select chart data by rows.
chartRowData.SelectData(worksheet("B2:F6"), ChartDataDirection.Row)
' Create a chart and specify its location.
Dim chartColumnData As Chart = worksheet.Charts.Add(ChartType.ColumnClustered)
chartColumnData.TopLeftCell = worksheet.Cells("K3")
chartColumnData.BottomRightCell = worksheet.Cells("N14")
' Select chart data by columns.
chartColumnData.SelectData(worksheet("B2:F6"), ChartDataDirection.Column)
' #End Region ' #CreateChartAndSelectDataDirection
End Sub
Private Shared Sub CreateChartWithComplexRange(ByVal workbook As Workbook)
' #Region "#CreateChartWithComplexRange"
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)
chart.TopLeftCell = worksheet.Cells("H2")
chart.BottomRightCell = worksheet.Cells("N14")
' Add chart series using worksheet ranges as the data sources.
chart.Series.Add(worksheet("D2"), worksheet("B3:B6"), worksheet("D3:D6"))
chart.Series.Add(worksheet("F2"), worksheet("B3:B6"), worksheet("F3:F6"))
' #End Region ' #CreateChartWithComplexRange
End Sub
Private Shared Sub CreateChartWithLiteralData(ByVal workbook As Workbook)
' #Region "#CreateChartWithLiteralData"
Dim worksheet As Worksheet = workbook.Worksheets(0)
workbook.Worksheets.ActiveWorksheet = worksheet
worksheet.Columns(0).WidthInCharacters = 2.0
' Create a chart and specify its location.
Dim chart As Chart = worksheet.Charts.Add(ChartType.ColumnClustered)
chart.TopLeftCell = worksheet.Cells("B2")
chart.BottomRightCell = worksheet.Cells("H15")
' Add a series bound to a set of literal data.
Dim series_of_literal As Series = chart.Series.Add(New CellValue() {"Jan", "Feb", "Mar", "Apr", "May", "Jun"}, New CellValue() {50, 100, 30, 104, 87, 150})
' #End Region ' #CreateChartWithLiteralData
End Sub
Private Shared Sub ChangeDataReference(ByVal workbook As Workbook)
' #Region "#ChangeDataReference"
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)
chart.TopLeftCell = worksheet.Cells("H2")
chart.BottomRightCell = worksheet.Cells("N14")
' Add series using a worksheet range as the data source.
chart.Series.Add(worksheet("D2"), worksheet("B3:B6"), worksheet("D3:D6"))
chart.Series.Add(worksheet("F2"), worksheet("B3:B6"), worksheet("F3:F6"))
' Change the data range for the series values.
chart.Series(1).Values = ChartData.FromRange(worksheet("E3:E6"))
' Specify the cell that is the source for the series name.
chart.Series(1).SeriesName.SetReference(worksheet("E2"))
' #End Region ' #ChangeDataReference
End Sub
End Class
End Namespace