Skip to content

Commit

Permalink
This closes #2052, support to sets the format of the chart series dat…
Browse files Browse the repository at this point in the history
…a label

- Add new field DataLabel in the ChartSeries data type
  • Loading branch information
xuri committed Dec 29, 2024
1 parent 9934bf5 commit 3f6ecff
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
3 changes: 3 additions & 0 deletions chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions drawing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
10 changes: 10 additions & 0 deletions xmlChart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
Expand All @@ -619,5 +628,6 @@ type ChartSeries struct {
Fill Fill
Line ChartLine
Marker ChartMarker
DataLabel ChartDataLabel
DataLabelPosition ChartDataLabelPositionType
}

0 comments on commit 3f6ecff

Please sign in to comment.