-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTrendlineActions.vb
More file actions
97 lines (82 loc) · 3.8 KB
/
TrendlineActions.vb
File metadata and controls
97 lines (82 loc) · 3.8 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
Imports DevExpress.Spreadsheet.Charts
Imports DevExpress.Spreadsheet.Drawings
Imports DevExpress.Spreadsheet
Imports System
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Namespace SpreadsheetChartAPIActions
Module TrendlineActions
Private Sub Trendlines(ByVal workbook As IWorkbook)
#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
End Sub
Private Sub TrendlineCustomization(ByVal workbook As IWorkbook)
#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
End Sub
Private Sub TrendlineLabel(ByVal workbook As IWorkbook)
#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
End Sub
End Module
End Namespace