This closes #2052, support to sets the format of the chart series data label

- Add new field DataLabel in the ChartSeries data type
This commit is contained in:
xuri 2024-12-29 12:30:28 +08:00
parent 9934bf5c86
commit 3f6ecffcca
No known key found for this signature in database
GPG Key ID: BA5E5BB1C948EDF7
4 changed files with 19 additions and 2 deletions

View File

@ -1214,8 +1214,8 @@ func setRichText(runs []RichTextRun) ([]xlsxR, error) {
}
// SetCellRichText provides a function to set cell with rich text by given
// worksheet. For example, set rich text on the A1 cell of the worksheet named
// Sheet1:
// worksheet name, cell reference and rich text runs. For example, set rich text
// on the A1 cell of the worksheet named Sheet1:
//
// package main
//

View File

@ -748,6 +748,7 @@ func (opts *Chart) parseTitle() {
// Fill
// Line
// Marker
// DataLabel
// DataLabelPosition
//
// Name: Set the name for the series. The name is displayed in the chart legend
@ -791,6 +792,8 @@ func (opts *Chart) parseTitle() {
// x
// auto
//
// DataLabel: This sets the format of the chart series data label.
//
// DataLabelPosition: This sets the position of the chart series data label.
//
// Set properties of the chart legend. The options that can be set are:

View File

@ -1028,6 +1028,10 @@ func (f *File) drawChartSeriesDLbls(i int, opts *Chart) *cDLbls {
dLbls.DLblPos = &attrValString{Val: stringPtr(chartDataLabelsPositionTypes[opts.Series[i].DataLabelPosition])}
}
}
dLbl := opts.Series[i].DataLabel
dLbls.SpPr = f.drawShapeFill(dLbl.Fill, dLbls.SpPr)
dLbls.TxPr = &cTxPr{BodyPr: aBodyPr{}, P: aP{PPr: &aPPr{DefRPr: aRPr{}}}}
drawChartFont(&dLbl.Font, &dLbls.TxPr.P.PPr.DefRPr)
return dLbls
}

View File

@ -484,6 +484,8 @@ type cNumCache struct {
// the specific formatting and positioning settings.
type cDLbls struct {
NumFmt *cNumFmt `xml:"numFmt"`
SpPr *cSpPr `xml:"spPr"`
TxPr *cTxPr `xml:"txPr"`
DLblPos *attrValString `xml:"dLblPos"`
ShowLegendKey *attrValBool `xml:"showLegendKey"`
ShowVal *attrValBool `xml:"showVal"`
@ -610,6 +612,13 @@ type ChartLine struct {
Width float64
}
// ChartDataLabel directly maps the format settings of the chart labels.
type ChartDataLabel struct {
Alignment Alignment
Font Font
Fill Fill
}
// ChartSeries directly maps the format settings of the chart series.
type ChartSeries struct {
Name string
@ -619,5 +628,6 @@ type ChartSeries struct {
Fill Fill
Line ChartLine
Marker ChartMarker
DataLabel ChartDataLabel
DataLabelPosition ChartDataLabelPositionType
}