@@ -80,12 +80,7 @@ func (f *File) addChart(opts *Chart, comboCharts []*Chart) {
8080 BackWall : & cThicknessSpPr {
8181 Thickness : & attrValInt {Val : intPtr (0 )},
8282 },
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 {},
8984 PlotVisOnly : & attrValBool {Val : boolPtr (false )},
9085 DispBlanksAs : & attrValString {Val : stringPtr (opts .ShowBlanksAs )},
9186 ShowDLblsOverMax : & attrValBool {Val : boolPtr (false )},
@@ -165,9 +160,7 @@ func (f *File) addChart(opts *Chart, comboCharts []*Chart) {
165160 Bubble : f .drawBubbleChart ,
166161 Bubble3D : f .drawBubbleChart ,
167162 }
168- if opts .Legend .Position == "none" {
169- xlsxChartSpace .Chart .Legend = nil
170- }
163+ xlsxChartSpace .Chart .drawChartLegend (opts )
171164 xlsxChartSpace .Chart .PlotArea .SpPr = f .drawShapeFill (opts .PlotArea .Fill , xlsxChartSpace .Chart .PlotArea .SpPr )
172165 xlsxChartSpace .Chart .PlotArea .DTable = f .drawPlotAreaDTable (opts )
173166 addChart := func (c , p * cPlotArea ) {
@@ -881,7 +874,8 @@ func (f *File) drawChartSeriesCat(v ChartSeries, opts *Chart) *cCat {
881874func (f * File ) drawChartSeriesVal (v ChartSeries , opts * Chart ) * cVal {
882875 val := & cVal {
883876 NumRef : & cNumRef {
884- F : v .Values ,
877+ F : v .Values ,
878+ NumCache : & cNumCache {},
885879 },
886880 }
887881 chartSeriesVal := map [ChartType ]* cVal {Scatter : nil , Bubble : nil , Bubble3D : nil }
@@ -935,7 +929,8 @@ func (f *File) drawChartSeriesXVal(v ChartSeries, opts *Chart) *cCat {
935929func (f * File ) drawChartSeriesYVal (v ChartSeries , opts * Chart ) * cVal {
936930 val := & cVal {
937931 NumRef : & cNumRef {
938- F : v .Values ,
932+ F : v .Values ,
933+ NumCache : & cNumCache {},
939934 },
940935 }
941936 chartSeriesYVal := map [ChartType ]* cVal {Scatter : val , Bubble : val , Bubble3D : val }
@@ -954,7 +949,8 @@ func (f *File) drawCharSeriesBubbleSize(v ChartSeries, opts *Chart) *cVal {
954949 }
955950 return & cVal {
956951 NumRef : & cNumRef {
957- F : fVal ,
952+ F : fVal ,
953+ NumCache : & cNumCache {},
958954 },
959955 }
960956}
@@ -1343,6 +1339,36 @@ func (f *File) drawChartLn(opts *ChartLine) *aLn {
13431339 }
13441340}
13451341
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+
13461372// drawingParser provides a function to parse drawingXML. In order to solve
13471373// the problem that the label structure is changed after serialization and
13481374// deserialization, two different structures: decodeWsDr and encodeWsDr are
0 commit comments