Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Secondary axis title is not displayed. #1926

Closed
vsemichev opened this issue Jun 19, 2024 · 2 comments · Fixed by #1928
Closed

Secondary axis title is not displayed. #1926

vsemichev opened this issue Jun 19, 2024 · 2 comments · Fixed by #1928
Labels
bug Something isn't working
Projects

Comments

@vsemichev
Copy link
Contributor

Description

I am trying to generate a combo chart with a secondary Y axis, however, the secondary Y axis is missing the title.

Steps to reproduce the issue:

Run the following code

package main

import (
	"fmt"
	"github.com/xuri/excelize/v2"
)

func main() {
	f := excelize.NewFile()
	defer func() {
		if err := f.Close(); err != nil {
			fmt.Println(err)
		}
	}()
	data := [][]interface{}{
		{"MonYear", "Aug-23", "Sep-23", "Oct-23", "Nov-23", "Dec-23", "Jan-24", "Feb-24", "Mar-24", "Apr-24", "May-24", "Jun-24"},
		{"a", 14, 14, 14, 12, 14, 14, 13, 13, 12, 13, 4},
		{"b", 3, 2, 4, 3, 2, 3, 2, 3, 2, 1, 0},
		{"c", 44198, 44366, 44683, 44857, 44762, 44949, 45005, 45157, 45483, 45574, 45435},
	}
	for idx, col := range data {
		cell, err := excelize.CoordinatesToCellName(idx+1, 1)
		if err != nil {
			fmt.Println(err)
			return
		}
		f.SetSheetCol("Sheet1", cell, &col)
	}
	disable := false
	if err := f.AddChart("Sheet1", "F1", &excelize.Chart{
		Type:       excelize.Col,
		Dimension:  excelize.ChartDimension{Width: 1080, Height: 576},
		XAxis:      excelize.ChartAxis{Font: excelize.Font{Color: "000000"}},
		YAxis:      excelize.ChartAxis{Font: excelize.Font{Color: "000000"}, MajorGridLines: true, Title: []excelize.RichTextRun{{Text: "Primary Axis"}}},
		VaryColors: &disable,
		PlotArea:   excelize.ChartPlotArea{ShowVal: true, NumFmt: excelize.ChartNumFmt{CustomNumFmt: "#\"\""}},
		Series: []excelize.ChartSeries{
			{
				Name:              "Sheet1!$B$1",
				Categories:        "Sheet1!$A$2:$A$12",
				Values:            "Sheet1!$B$2:$B$12",
				Fill:              excelize.Fill{Type: "pattern", Color: []string{"1F77B4"}, Pattern: 1},
				DataLabelPosition: excelize.ChartDataLabelsPositionInsideEnd,
			},
			{
				Name:              "Sheet1!$C$1",
				Categories:        "Sheet1!$A$2:$A$12",
				Values:            "Sheet1!$C$2:$C$12",
				Fill:              excelize.Fill{Type: "pattern", Color: []string{"FF7F0E"}, Pattern: 1},
				DataLabelPosition: excelize.ChartDataLabelsPositionInsideEnd,
			},
		},
		Title: []excelize.RichTextRun{
			{
				Text: "Combo column and line chart",
			},
		},
	},
		&excelize.Chart{
			Type:       excelize.Line,
			Dimension:  excelize.ChartDimension{Width: 1080, Height: 576},
			YAxis:      excelize.ChartAxis{Secondary: true, Font: excelize.Font{Color: "000000"}, Title: []excelize.RichTextRun{{Font: &excelize.Font{Color: "000000"}, Text: "Secondary Axis"}}},
			VaryColors: &disable,
			PlotArea:   excelize.ChartPlotArea{ShowVal: true, NumFmt: excelize.ChartNumFmt{CustomNumFmt: "#\"\""}},
			Series: []excelize.ChartSeries{
				{
					Name:              "Sheet1!$D$1",
					Categories:        "Sheet1!$A$2:$A$12",
					Values:            "Sheet1!$D$2:$D$12",
					Fill:              excelize.Fill{Type: "pattern", Color: []string{"2CA02C"}, Pattern: 1},
					DataLabelPosition: excelize.ChartDataLabelsPositionAbove,
					Marker:            excelize.ChartMarker{Symbol: "none"},
				},
			},
		}); err != nil {
		fmt.Println(err)
		return
	}
	// Save spreadsheet by the given path.
	if err := f.SaveAs("Book1.xlsx"); err != nil {
		fmt.Println(err)
	}
}

Describe the results you received:

Combo bar + line chart. Primary Y-axis has the title, but the secondary Y-axis does not.

Describe the results you expected:

I expect the secondary Y-axis to have a title that I provided.

Output of go version:

go version go1.22.4 darwin/arm64

Excelize version or commit ID:

v2.8.2-0.20240617135415-1a99dd4a233c

Environment details (OS, Microsoft Excel™ version, physical, etc.):

MacOS Sonoma 14.5, Microsoft Excel for Mac Version 16.86 (24060916)

@xuri
Copy link
Member

xuri commented Jun 19, 2024

Thanks for your issue. It seems we need remove this line of code in the drawing.go, would you like to create a pull request for help us fix that?

@xuri xuri added the bug Something isn't working label Jun 20, 2024
vsemichev added a commit to vsemichev/excelize that referenced this issue Jun 20, 2024
@vsemichev vsemichev mentioned this issue Jun 20, 2024
10 tasks
@vsemichev
Copy link
Contributor Author

Hi @xuri, per your instruction I have just submitted a new pull request. Thank you for a quick response!

@xuri xuri linked a pull request Jun 20, 2024 that will close this issue
10 tasks
@xuri xuri closed this as completed in 4e6457a Jun 21, 2024
@xuri xuri added this to Bugfix in v2.9.0 Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
v2.9.0
Bugfix
Development

Successfully merging a pull request may close this issue.

2 participants