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

Single element donut charts renders as an empty canvas #203

Open
sameeraaperera opened this issue Oct 20, 2022 · 1 comment
Open

Single element donut charts renders as an empty canvas #203

sameeraaperera opened this issue Oct 20, 2022 · 1 comment

Comments

@sameeraaperera
Copy link

I had a requirement to generate charts that somtimes contain only 1 element(100%)/ But having only one element as input values ends up with just the canvas. Single item donut charts seem to have some custom handling here .

if len(values) == 1 {

func main() {
	donut := chart.DonutChart{
		Width:  512,
		Height: 512,
		Values: []chart.Value{
			{
				Value: 1,
			},
		},
	}
	f, _ := os.Create("donut.png")
	donut.Render(chart.PNG, f)
	
}

Output(just a white canvas):
donut

Workaround
As a workaround I ended up with adding an extra value with a very small value(1e-7) and very small stroke width which triggered the usual rendering. Its not ideal as you can still see a tiny white line but its something.

Values: []chart.Value{
			{
				Value: 1,
				Style: chart.Style{
					StrokeWidth: 1e-7,
				},
			},
			{
				Value: 1e-7,
				Style: chart.Style{
					StrokeWidth: 1e-7,
				},
			},
		},

Output
donut

@AlejandroTorreblanca
Copy link

#205 Fixes the issue.

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

No branches or pull requests

2 participants