wcharczuk / go-chart

go chart is a basic charting library in go.
MIT License
3.99k stars 326 forks source link

SVG: title is incorrectly positioned/rotated when using YAxis #55

Open d4l3k opened 7 years ago

d4l3k commented 7 years ago

When I added a YAxis Name to my chart it caused the title to be rotated and positioned weirdly. This only happens while using the charts.SVG renderer. Switching to charts.PNG fixes the issue.

Example file: https://fn.lc/s/0.svg

NameStyle: chart.StyleShow()

2017-09-19-205024_1002x391_scrot

No NameStyle

2017-09-19-205238_1028x388_scrot

Relevant Code

graph := chart.Chart{
    Title:      fmt.Sprintf("%s vs. %s", gp.Name(dim), gp.OutputName()),
    TitleStyle: chart.StyleShow(),
    XAxis: chart.XAxis{
        Name:      gp.Name(dim),
        NameStyle: chart.StyleShow(),
        Style:     chart.StyleShow(),
    },
    YAxis: chart.YAxis{
        Name: gp.OutputName(),
        NameStyle: chart.StyleShow(), // Commenting this line fixes the issue.
        Style: chart.StyleShow(),
    },
    Background: chart.Style{
        Padding: chart.Box{
            Top:    20,
            Left:   20,
            Bottom: 20,
            Right:  20,
        },
    },
}
graph.Elements = []chart.Renderable{
    chart.Legend(&graph),
}

graph.Series = append(
    graph.Series,
    chart.ContinuousSeries{
        Name:    "Mean",
        XValues: x,
        YValues: means,
    },
    chart.ContinuousSeries{
        Name:    "+1σ",
        XValues: x,
        YValues: uppers,
    },
    chart.ContinuousSeries{
        Name:    "-1σ",
        XValues: x,
        YValues: lowers,
    },
)

graph.Series = append(
    graph.Series,
    chart.ContinuousSeries{
        Name:    "Known",
        XValues: knownX,
        YValues: knownY,
        Style: chart.Style{
            Show:        true,
            StrokeWidth: chart.Disabled,
            DotWidth:    5,
        },
    },
)

if err := graph.Render(chart.SVG, w); err != nil {
    return err
}
d4l3k commented 7 years ago

This also appears to be the same issue at https://github.com/wcharczuk/go-chart/issues/44, except #44 doesn't mention this is incorrect behavior.

imJohly commented 2 years ago

Any work on this (seeing as it has been 4 years)? Having the same issue, would love to have this fixed.