Skip to content

Horizontal axis text alignment #2025

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

Closed
xuexnGo opened this issue Nov 12, 2024 · 1 comment
Closed

Horizontal axis text alignment #2025

xuexnGo opened this issue Nov 12, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@xuexnGo
Copy link

xuexnGo commented Nov 12, 2024

Can I set the text alignment direction for the horizontal axis
image

@xuri xuri closed this as completed in 5f446f2 Nov 15, 2024
@xuri
Copy link
Member

xuri commented Nov 15, 2024

Thanks for your issue. I added new field Alignment in the ChartAxis data type to support set chart axis text direction and rotation. For example:

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)
        }
    }()
    for idx, row := range [][]interface{}{
        {nil, "Apple", "Orange", "Pear"}, {"Small", 2, 3, 3},
        {"Normal", 5, 2, 4}, {"Large", 6, 7, 8},
    } {
        cell, err := excelize.CoordinatesToCellName(1, idx+1)
        if err != nil {
            fmt.Println(err)
            return
        }
        f.SetSheetRow("Sheet1", cell, &row)
    }
    if err := f.AddChart("Sheet1", "E1", &excelize.Chart{
        Type: excelize.Col3DClustered,
        Series: []excelize.ChartSeries{
            {
                Name:       "Sheet1!$A$2",
                Categories: "Sheet1!$B$1:$D$1",
                Values:     "Sheet1!$B$2:$D$2",
            },
            {
                Name:       "Sheet1!$A$3",
                Categories: "Sheet1!$B$1:$D$1",
                Values:     "Sheet1!$B$3:$D$3",
            },
            {
                Name:       "Sheet1!$A$4",
                Categories: "Sheet1!$B$1:$D$1",
                Values:     "Sheet1!$B$4:$D$4",
            }},
        Title: []excelize.RichTextRun{
            {
                Text: "Fruit 3D Clustered Column Chart",
            },
        },
        XAxis: excelize.ChartAxis{
+           Alignment: excelize.Alignment{
+               Vertical:     "wordArtVertRtl",
+               TextRotation: 0,
+           },
        },
    }); err != nil {
        fmt.Println(err)
        return
    }
    // Save spreadsheet by the given path.
    if err := f.SaveAs("Book1.xlsx"); err != nil {
        fmt.Println(err)
    }
}

Please upgrade to the master branch code by following command, and this feature will be released in the next version 2.9.1.

go get -u github.com/xuri/excelize/v2@master

@xuri xuri added the enhancement New feature or request label Nov 15, 2024
@xuri xuri moved this to Features in Excelize v2.9.1 Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
Status: Features
Development

No branches or pull requests

2 participants