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

Fix bar chart y label #180

Closed

Conversation

eduardhasanaj
Copy link

This pull request fixes the following issues:

  1. YAxis Label not drawn at all for BarChart.
  2. Add support for label padding

Instead of using BarChart.drawYAxis we can use YAxis.Render method.
I am unclear why this was not used in the first place otherwise we have code duplication.

Please note that this branch contains features of an open pull request. PM me after it is approved so I can make any required changes.
After the fix we can see the label
output

code

package main

//go:generate go run main.go

import (
	"os"

	"github.com/wcharczuk/go-chart/v2"
)

func main() {
	graph := chart.BarChart{
		Title: "Test Bar Chart",
		Background: chart.Style{
			Padding: chart.Box{
				Top: 40,
			},
		},
		Height:   512,
		BarWidth: 60,
		YAxis: chart.YAxis{
			Name: "Label Y",
			NameStyle: chart.Style{
				FontSize:            14,
				Padding:             chart.NewBox(0, 40, 20, 0),
				TextRotationDegrees: 0,
			},
		},
		Bars: []chart.Value{
			{Value: 5.25, Label: "Blue"},
			{Value: 4.88, Label: "Green"},
			{Value: 4.74, Label: "Gray"},
			{Value: 3.22, Label: "Orange"},
			{Value: 3, Label: "Test"},
			{Value: 2.27, Label: "??"},
			{Value: 1, Label: "!!"},
		},
	}

	f, _ := os.Create("output.png")
	defer f.Close()
	graph.Render(chart.PNG, f)
}

@wcharczuk wcharczuk deleted the branch wcharczuk:master September 11, 2023 16:21
@wcharczuk wcharczuk closed this Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants