Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

piechart source pure

Package piechart provides functionality to render a pie chart as an SVG image. It takes a list of PieSlice objects, e...

Readme View source

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

Overview

Package piechart provides functionality to render a pie chart as an SVG image. It takes a list of PieSlice objects, each representing a slice of the pie with a value, color, and label, and generates an SVG representation of the pie chart.

Functions 1

func Render

1func Render(slices []PieSlice, title string) string
source

Render creates an SVG pie chart from given slices (value, color and label). It returns an img svg markup as a string, including a markdown header if a non-empty title is provided.

Types 1

type PieSlice

struct
1type PieSlice struct {
2	Value float64
3	Color string
4	Label string
5}
source

Imports 4

Source Files 4