Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

/p/samcrew/piechart/v0

Directory · 4 Files
README.md Open

piechart - SVG pie charts

Generate pie charts with legends as SVG markup for gnoweb rendering.

Usage

 1slices := []piechart.PieSlice{
 2    {Value: 30, Color: "#ff6b6b", Label: "Frontend"},
 3    {Value: 25, Color: "#4ecdc4", Label: "Backend"},
 4    {Value: 20, Color: "#45b7d1", Label: "DevOps"},
 5    {Value: 15, Color: "#96ceb4", Label: "Mobile"},
 6    {Value: 10, Color: "#ffeaa7", Label: "Other"},
 7}
 8
 9// With title
10titledChart := piechart.Render(slices, "Team Distribution")
11
12// Without title  
13untitledChart := piechart.Render(slices, "")

API Reference

 1type PieSlice struct {
 2    Value float64 // Numeric value for the slice
 3    Color string  // Hex color code (e.g., "#ff6b6b")
 4    Label string  // Display label for the slice
 5}
 6
 7// slices: Array of PieSlice structs containing the data
 8// title: Chart title (empty string for no title)
 9// Returns: SVG markup as a string
10func Render(slices []PieSlice, title string) string

Live Example