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

Single element donut charts renders as an empty canvas #203

@sameeraaperera

Description

@sameeraaperera

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions