Skip to content

Commit 3f6ecff

Browse files
committed
This closes qax-os#2052, support to sets the format of the chart series data label
- Add new field DataLabel in the ChartSeries data type
1 parent 9934bf5 commit 3f6ecff

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

cell.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1214,8 +1214,8 @@ func setRichText(runs []RichTextRun) ([]xlsxR, error) {
12141214
}
12151215

12161216
// SetCellRichText provides a function to set cell with rich text by given
1217-
// worksheet. For example, set rich text on the A1 cell of the worksheet named
1218-
// Sheet1:
1217+
// worksheet name, cell reference and rich text runs. For example, set rich text
1218+
// on the A1 cell of the worksheet named Sheet1:
12191219
//
12201220
// package main
12211221
//

chart.go

+3
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@ func (opts *Chart) parseTitle() {
748748
// Fill
749749
// Line
750750
// Marker
751+
// DataLabel
751752
// DataLabelPosition
752753
//
753754
// Name: Set the name for the series. The name is displayed in the chart legend
@@ -791,6 +792,8 @@ func (opts *Chart) parseTitle() {
791792
// x
792793
// auto
793794
//
795+
// DataLabel: This sets the format of the chart series data label.
796+
//
794797
// DataLabelPosition: This sets the position of the chart series data label.
795798
//
796799
// Set properties of the chart legend. The options that can be set are:

drawing.go

+4
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,10 @@ func (f *File) drawChartSeriesDLbls(i int, opts *Chart) *cDLbls {
10281028
dLbls.DLblPos = &attrValString{Val: stringPtr(chartDataLabelsPositionTypes[opts.Series[i].DataLabelPosition])}
10291029
}
10301030
}
1031+
dLbl := opts.Series[i].DataLabel
1032+
dLbls.SpPr = f.drawShapeFill(dLbl.Fill, dLbls.SpPr)
1033+
dLbls.TxPr = &cTxPr{BodyPr: aBodyPr{}, P: aP{PPr: &aPPr{DefRPr: aRPr{}}}}
1034+
drawChartFont(&dLbl.Font, &dLbls.TxPr.P.PPr.DefRPr)
10311035
return dLbls
10321036
}
10331037

xmlChart.go

+10
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,8 @@ type cNumCache struct {
484484
// the specific formatting and positioning settings.
485485
type cDLbls struct {
486486
NumFmt *cNumFmt `xml:"numFmt"`
487+
SpPr *cSpPr `xml:"spPr"`
488+
TxPr *cTxPr `xml:"txPr"`
487489
DLblPos *attrValString `xml:"dLblPos"`
488490
ShowLegendKey *attrValBool `xml:"showLegendKey"`
489491
ShowVal *attrValBool `xml:"showVal"`
@@ -610,6 +612,13 @@ type ChartLine struct {
610612
Width float64
611613
}
612614

615+
// ChartDataLabel directly maps the format settings of the chart labels.
616+
type ChartDataLabel struct {
617+
Alignment Alignment
618+
Font Font
619+
Fill Fill
620+
}
621+
613622
// ChartSeries directly maps the format settings of the chart series.
614623
type ChartSeries struct {
615624
Name string
@@ -619,5 +628,6 @@ type ChartSeries struct {
619628
Fill Fill
620629
Line ChartLine
621630
Marker ChartMarker
631+
DataLabel ChartDataLabel
622632
DataLabelPosition ChartDataLabelPositionType
623633
}

0 commit comments

Comments
 (0)