@@ -80,12 +80,7 @@ func (f *File) addChart(opts *Chart, comboCharts []*Chart) {
80
80
BackWall : & cThicknessSpPr {
81
81
Thickness : & attrValInt {Val : intPtr (0 )},
82
82
},
83
- PlotArea : & cPlotArea {},
84
- Legend : & cLegend {
85
- LegendPos : & attrValString {Val : stringPtr (chartLegendPosition [opts .Legend .Position ])},
86
- Overlay : & attrValBool {Val : boolPtr (false )},
87
- },
88
-
83
+ PlotArea : & cPlotArea {},
89
84
PlotVisOnly : & attrValBool {Val : boolPtr (false )},
90
85
DispBlanksAs : & attrValString {Val : stringPtr (opts .ShowBlanksAs )},
91
86
ShowDLblsOverMax : & attrValBool {Val : boolPtr (false )},
@@ -165,9 +160,7 @@ func (f *File) addChart(opts *Chart, comboCharts []*Chart) {
165
160
Bubble : f .drawBubbleChart ,
166
161
Bubble3D : f .drawBubbleChart ,
167
162
}
168
- if opts .Legend .Position == "none" {
169
- xlsxChartSpace .Chart .Legend = nil
170
- }
163
+ xlsxChartSpace .Chart .drawChartLegend (opts )
171
164
xlsxChartSpace .Chart .PlotArea .SpPr = f .drawShapeFill (opts .PlotArea .Fill , xlsxChartSpace .Chart .PlotArea .SpPr )
172
165
xlsxChartSpace .Chart .PlotArea .DTable = f .drawPlotAreaDTable (opts )
173
166
addChart := func (c , p * cPlotArea ) {
@@ -881,7 +874,8 @@ func (f *File) drawChartSeriesCat(v ChartSeries, opts *Chart) *cCat {
881
874
func (f * File ) drawChartSeriesVal (v ChartSeries , opts * Chart ) * cVal {
882
875
val := & cVal {
883
876
NumRef : & cNumRef {
884
- F : v .Values ,
877
+ F : v .Values ,
878
+ NumCache : & cNumCache {},
885
879
},
886
880
}
887
881
chartSeriesVal := map [ChartType ]* cVal {Scatter : nil , Bubble : nil , Bubble3D : nil }
@@ -935,7 +929,8 @@ func (f *File) drawChartSeriesXVal(v ChartSeries, opts *Chart) *cCat {
935
929
func (f * File ) drawChartSeriesYVal (v ChartSeries , opts * Chart ) * cVal {
936
930
val := & cVal {
937
931
NumRef : & cNumRef {
938
- F : v .Values ,
932
+ F : v .Values ,
933
+ NumCache : & cNumCache {},
939
934
},
940
935
}
941
936
chartSeriesYVal := map [ChartType ]* cVal {Scatter : val , Bubble : val , Bubble3D : val }
@@ -954,7 +949,8 @@ func (f *File) drawCharSeriesBubbleSize(v ChartSeries, opts *Chart) *cVal {
954
949
}
955
950
return & cVal {
956
951
NumRef : & cNumRef {
957
- F : fVal ,
952
+ F : fVal ,
953
+ NumCache : & cNumCache {},
958
954
},
959
955
}
960
956
}
@@ -1343,6 +1339,36 @@ func (f *File) drawChartLn(opts *ChartLine) *aLn {
1343
1339
}
1344
1340
}
1345
1341
1342
+ // drawChartLegend provides a function to draw the c:legend element.
1343
+ func (c * cChart ) drawChartLegend (opts * Chart ) {
1344
+ if opts .Legend .Position == "none" {
1345
+ c .Legend = nil
1346
+ return
1347
+ }
1348
+ if c .Legend == nil {
1349
+ c .Legend = & cLegend {
1350
+ LegendPos : & attrValString {Val : stringPtr (chartLegendPosition [opts .Legend .Position ])},
1351
+ Overlay : & attrValBool {Val : boolPtr (false )},
1352
+ }
1353
+ }
1354
+ if opts .Legend .Font != nil {
1355
+ c .Legend .TxPr = & cTxPr {P : aP {PPr : & aPPr {}}}
1356
+ drawChartFont (opts .Legend .Font , & c .Legend .TxPr .P .PPr .DefRPr )
1357
+ }
1358
+ for k := range opts .Series {
1359
+ font := opts .Series [k ].Legend .Font
1360
+ if font == nil {
1361
+ continue
1362
+ }
1363
+ legendEntry := cLegendEntry {
1364
+ IDx : & attrValInt {Val : intPtr (k + opts .order )},
1365
+ TxPr : & cTxPr {P : aP {PPr : & aPPr {}}},
1366
+ }
1367
+ drawChartFont (font , & legendEntry .TxPr .P .PPr .DefRPr )
1368
+ c .Legend .LegendEntry = append (c .Legend .LegendEntry , legendEntry )
1369
+ }
1370
+ }
1371
+
1346
1372
// drawingParser provides a function to parse drawingXML. In order to solve
1347
1373
// the problem that the label structure is changed after serialization and
1348
1374
// deserialization, two different structures: decodeWsDr and encodeWsDr are
0 commit comments