-
Notifications
You must be signed in to change notification settings - Fork 6
/
charts.go
87 lines (83 loc) · 2.23 KB
/
charts.go
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
package gsheet
import (
"google.golang.org/api/sheets/v4"
)
// Creates a basic chart series
func createBasicChartSeries(values [][]interface{}) []*sheets.BasicChartSeries {
var BasicChartSeries []*sheets.BasicChartSeries
for i := range values {
if i == 0 {
continue
}
BasicChartSeries = append(BasicChartSeries, &sheets.BasicChartSeries{
Series: &sheets.ChartData{
SourceRange: &sheets.ChartSourceRange{
Sources: []*sheets.GridRange{
{ //A2:O2
SheetId: 1023,
StartRowIndex: int64(i),
EndRowIndex: int64(i + 1),
StartColumnIndex: 0,
EndColumnIndex: int64(len(values[i])),
},
},
},
},
})
}
return BasicChartSeries
}
// Creates Histograms series used to populate the histogram chart later on
func createHistogramSeries(values [][]interface{}) []*sheets.HistogramSeries {
var HistogramSeries []*sheets.HistogramSeries
for i := range values {
if i == 0 {
continue
}
HistogramSeries = append(HistogramSeries, &sheets.HistogramSeries{
Data: &sheets.ChartData{
SourceRange: &sheets.ChartSourceRange{
Sources: []*sheets.GridRange{
{ //A2:O2
SheetId: 1023,
StartRowIndex: int64(i),
EndRowIndex: int64(i + 1),
StartColumnIndex: 0,
EndColumnIndex: int64(len(values[i])),
},
},
},
},
})
}
return HistogramSeries
}
// Creates a basic chart specification
func createBasicChartSpec(legendPosition, chartype, stackedType string, sourceSheetId int64, values [][]interface{}, basicChartSeries []*sheets.BasicChartSeries) *sheets.BasicChartSpec {
var BasicChartSpec *sheets.BasicChartSpec
BasicChartSpec = &sheets.BasicChartSpec{
HeaderCount: 1,
Series: basicChartSeries,
LegendPosition: "BOTTOM_LEGEND",
ChartType: "COLUMN",
StackedType: "STACKED",
Domains: []*sheets.BasicChartDomain{
{
Domain: &sheets.ChartData{
SourceRange: &sheets.ChartSourceRange{
Sources: []*sheets.GridRange{
{
SheetId: 1023,
StartRowIndex: 0,
EndRowIndex: 1,
StartColumnIndex: 0,
EndColumnIndex: int64(len(values[0])),
},
},
},
},
},
},
}
return BasicChartSpec
}