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

Rendering A Pie Chart with a Title - Title over top of chart #226

Open
HSchmale16 opened this issue Jul 7, 2024 · 1 comment
Open

Rendering A Pie Chart with a Title - Title over top of chart #226

HSchmale16 opened this issue Jul 7, 2024 · 1 comment

Comments

@HSchmale16
Copy link

I'm trying to make it render some nice looking plots using this library. However I'm having issues getting the title to render right using the chart.PieChart{} interface. The title renders overs the pie chart.

How can I make it so the chart is smaller than the title section so the title is an actual header.

image

func renderPieChart(parties map[string]float64, member DB_CongressMember) ([]byte, error) {
	values := make([]chart.Value, 0, len(parties))
	for k, v := range parties {
		values = append(values, chart.Value{
			Value: v,
			Label: k,
			Style: chart.Style{
				FillColor: getColorForParty(k),
			},
		})
	}

	// Create a new pie chart
	pie := chart.PieChart{
		Width:  512,
		Height: 512,
		Values: values,
		Title:  "Which Parties " + member.Name + " works with",
	}

	// Render the pie chart as a PNG image
	b := bytes.NewBuffer([]byte{})
	err := pie.Render(chart.PNG, b)
	if err != nil {
		return nil, err
	}

	return b.Bytes(), nil
}
@HSchmale16
Copy link
Author

I did a little bit more testing, and it occurs with other renderers. I can't seem to get it to honor the Style information passed in when there's only one value included in the Values list.

Not sure what is significant about that, but I find it weird.

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

1 participant