-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTrendlineActions.vb
More file actions
102 lines (85 loc) · 4.17 KB
/
TrendlineActions.vb
File metadata and controls
102 lines (85 loc) · 4.17 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
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 TrendlineActions
Private Sub New()
End Sub
Public Shared TrendlinesAction As Action(Of Workbook) = AddressOf Trendlines
Public Shared TrendlineCustomizationAction As Action(Of Workbook) = AddressOf TrendlineCustomization
Public Shared TrendlineLabelAction As Action(Of Workbook) = AddressOf TrendlineLabel
Private Shared Sub Trendlines(ByVal workbook As Workbook)
#Region "#Trendlines"
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.ColumnStacked)
chart.SelectData(worksheet("C2:F3"), ChartDataDirection.Row)
chart.TopLeftCell = worksheet.Cells("H2")
chart.BottomRightCell = worksheet.Cells("N14")
' Show data labels.
chart.Views(0).DataLabels.ShowValue = True
' Display a polynomial trendline.
chart.Series(0).Trendlines.Add(ChartTrendlineType.Polynomial)
#End Region ' #Trendlines
End Sub
Private Shared Sub TrendlineCustomization(ByVal workbook As Workbook)
#Region "#TrendlineCustomization"
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.ScatterMarkers)
chart.SelectData(worksheet("C2:F3"), ChartDataDirection.Row)
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.AutoMin = False
axis.Scaling.Min = 0.6
axis.Scaling.Max = 1.0
chart.PrimaryAxes(1).MajorGridlines.Visible = False
' Display a polynomial trendline.
chart.Series(0).Trendlines.Add(ChartTrendlineType.Polynomial)
' Customize the trendline.
Dim tline As Trendline = chart.Series(0).Trendlines(0)
tline.DisplayEquation = True
tline.CustomName = "Trend"
tline.DisplayRSquare = True
tline.Backward = 1
tline.Forward = 2
tline.Outline.SetSolidFill(Color.Red)
#End Region ' #TrendlineCustomization
End Sub
Private Shared Sub TrendlineLabel(ByVal workbook As Workbook)
#Region "#TrendlineLabel"
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.ScatterMarkers)
chart.SelectData(worksheet("C2:F3"), ChartDataDirection.Row)
chart.TopLeftCell = worksheet.Cells("H2")
chart.BottomRightCell = worksheet.Cells("N14")
' Display a polynomial trendline.
chart.Series(0).Trendlines.Add(ChartTrendlineType.Polynomial)
' Customize the trendline.
Dim tline As Trendline = chart.Series(0).Trendlines(0)
tline.DisplayEquation = True
tline.CustomName = "Trend"
tline.DisplayRSquare = True
tline.Outline.SetSolidFill(Color.Red)
' Format the trend label.
Dim tlabel As TrendlineLabel = tline.Label
tlabel.Font.Name = "Tahoma"
tlabel.Font.Italic = True
tlabel.Fill.SetGradientFill(ShapeGradientType.Linear, Color.Orange, Color.White)
' Position the label in the right quarter of the chart area.
tlabel.Layout.Left.SetPosition(LayoutMode.Edge, 0.75)
#End Region ' #TrendlineLabel
End Sub
End Class
End Namespace