Skip to content
This repository has been archived by the owner on Aug 23, 2024. It is now read-only.

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants