gosvgchart

package module
v0.10.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2025 License: MIT Imports: 5 Imported by: 0

README

GoSVGChart

A simple, declarative SVG chart library for Go. This library allows you to create various chart types with a clean, chainable API or a simple markdown-like text format.

Features

  • Multiple ways to create charts:
    • Purely declarative Go API with method chaining
    • Simple markdown-like text format (great for LLM-generated charts)
    • Web server for dynamic chart generation
    • Goldmark extension for embedding charts in markdown documents
  • No external dependencies for core functionality (uses only the Go standard library)
  • Generates responsive SVG output that adapts to container size while maintaining aspect ratio
  • Supports multiple chart types:
    • Line charts (with multiple series support)
    • Bar charts (with multiple series support, grouped or stacked)
    • Pie/Donut charts
    • Heatmap charts (GitHub-style activity heatmap or feedback visualization)
  • Multiple series support for line and bar charts
  • Customizable styling and options
  • Automatic dark mode support for system color scheme adaptation

Responsive SVG Output

All charts generated with GoSVGChart are fully responsive. The SVG output uses:

  • width="100%" to fill the container width
  • height="auto" to maintain the aspect ratio
  • viewBox and preserveAspectRatio to ensure proper scaling

This means the dimensions you specify (via SetSize() or in the markdown format) define the aspect ratio rather than fixed pixel sizes. Your charts will automatically adapt to different screen sizes and container widths while maintaining their proportions.

<!-- Example of the responsive SVG output -->
<svg width="100%" height="auto" viewBox="0 0 800 500" preserveAspectRatio="xMidYMid meet" xmlns="http://www.w3.org/2000/svg">
  <!-- Chart content -->
</svg>

Dark Mode Support

SVGs created with GoSVGChart automatically adapt to the user's system color scheme preference (light/dark mode). This feature uses CSS and the prefers-color-scheme media query to switch between defined color themes without requiring JavaScript.

Dark Mode (Enabled by Default)

All charts created with GoSVGChart have dark mode support enabled by default. This means your charts will automatically adapt to the user's system preferences without any additional configuration.

If you want to customize the color themes or disable dark mode, you can use the following methods:

// Create your chart normally
chart := gosvgchart.NewLineChart().
    SetTitle("Chart with Custom Themes").
    SetSize(600, 400).
    SetData([]float64{120, 250, 180, 310})

// Dark mode is already enabled by default
// You can customize the dark theme colors if desired:
chart.SetDarkTheme(
    "#121212", // Background color
    "#ffffff", // Text color
    "#aaaaaa", // Axis color
    "#333333", // Grid color
)

// You can also customize the light theme colors:
chart.SetLightTheme(
    "#ffffff", // Background color
    "#000000", // Text color
    "#666666", // Axis color 
    "#dddddd", // Grid color
)

// If you need to disable dark mode for some reason:
chart.EnableDarkModeSupport(false)

When the chart is rendered, it will automatically adapt based on the system's color scheme preferences. This works in modern browsers and SVG viewers that support the CSS prefers-color-scheme media query.

See examples/dark_mode_example.go for a complete example.

Multiple Series Support

GoSVGChart supports multiple data series for line and bar charts. This allows you to compare different datasets in the same chart.

Using the Go API
// Create a line chart with multiple series
chart := gosvgchart.NewLineChart().
    SetTitle("Monthly Sales by Product").
    SetSize(800, 500).
    SetLabels([]string{"Jan", "Feb", "Mar", "Apr", "May", "Jun"})

// Add multiple series
chart.AddSeries("Product A", []float64{120, 150, 180, 210, 240, 270})
chart.AddSeries("Product B", []float64{200, 180, 160, 140, 120, 100})
chart.AddSeries("Product C", []float64{50, 80, 110, 140, 170, 200})

// Set colors for the series
chart.SetSeriesColors([]string{"#4285F4", "#EA4335", "#FBBC05", "#34A853"})

// Enable legend
chart.ShowLegend = true

// Render the chart
svg := chart.Render()
Using the Markdown Format

For line charts with multiple series:

linechart
title: Monthly Sales by Product
width: 800
height: auto
seriescolors: #4285F4, #EA4335, #FBBC05, #34A853

series:
Month | Product A | Product B | Product C
Jan | 120 | 200 | 50
Feb | 150 | 180 | 80
Mar | 180 | 160 | 110
Apr | 210 | 140 | 140
May | 240 | 120 | 170
Jun | 270 | 100 | 200

For bar charts with multiple series (grouped):

barchart
title: Quarterly Revenue by Region
width: 800
height: auto
stacked: false
seriescolors: #4285F4, #EA4335, #FBBC05, #34A853

series:
Quarter | North | South | East | West
Q1 | 150 | 120 | 90 | 180
Q2 | 180 | 140 | 110 | 200
Q3 | 210 | 160 | 130 | 220
Q4 | 240 | 180 | 150 | 240

For stacked bar charts:

barchart
title: Quarterly Revenue by Region
width: 800
height: auto
stacked: true
seriescolors: #4285F4, #EA4335, #FBBC05, #34A853

series:
Quarter | North | South | East | West
Q1 | 150 | 120 | 90 | 180
Q2 | 180 | 140 | 110 | 200
Q3 | 210 | 160 | 130 | 220
Q4 | 240 | 180 | 150 | 240

For more examples of multiple series in markdown format, see examples/multiple_series_markdown.md.

Installation

go get github.com/riclib/gosvgchart

Usage (Go API)

Line Chart
import (
    "github.com/riclib/gosvgchart"
    "os"
)

func main() {
    // Create a line chart
    chart := gosvgchart.New().
        SetTitle("Monthly Sales").
        SetData([]float64{120, 250, 180, 310, 270, 390}).
        SetLabels([]string{"Jan", "Feb", "Mar", "Apr", "May", "Jun"}).
        SetColors([]string{"#3498db"}).
        SetSize(600, 400)

    // Render to SVG string
    svg := chart.Render()

    // Save to file
    os.WriteFile("line_chart.svg", []byte(svg), 0644)
}
Bar Chart
// Create a bar chart
chart := gosvgchart.New().
    SetTitle("Quarterly Revenue").
    SetData([]float64{850, 940, 1100, 1200}).
    SetLabels([]string{"Q1", "Q2", "Q3", "Q4"}).
    SetColors([]string{"#2ecc71", "#e74c3c", "#f39c12", "#9b59b6"}).
    SetSize(600, 400)

// Render to SVG string
svg := chart.Render()
Pie Chart
// Create a pie chart
chart := gosvgchart.New().
    SetTitle("Market Share").
    SetData([]float64{35, 25, 20, 15, 5}).
    SetLabels([]string{"Product A", "Product B", "Product C", "Product D", "Others"}).
    SetColors([]string{"#3498db", "#2ecc71", "#e74c3c", "#f39c12", "#9b59b6"}).
    SetSize(600, 500)

// For a donut chart, add:
chart.SetDonutHole(0.6) // 0-0.9, where 0 is a pie chart and 0.9 is a thin donut

// Render to SVG string
svg := chart.Render()
Using Auto-Height with the Go API

You can use the SetAutoHeight method to automatically calculate the height based on the width:

// Create a chart with auto-height
chart := gosvgchart.New().
    SetTitle("Monthly Sales").
    SetData([]float64{120, 250, 180, 310, 270, 390}).
    SetLabels([]string{"Jan", "Feb", "Mar", "Apr", "May", "Jun"}).
    SetColors([]string{"#3498db"}).
    SetSize(800, 0). // Height will be ignored when auto-height is enabled
    SetAutoHeight(true)

// Render to SVG string
svg := chart.Render()
Heatmap Chart (GitHub-style)
import (
    "github.com/riclib/gosvgchart"
    "time"
)

// Create a heatmap chart
chart := gosvgchart.NewHeatmapChart().
    SetTitle("GitHub Contributions").
    SetSize(800, 200)

// Set activity data (dates must be in YYYY-MM-DD format)
chart.SetLabels([]string{
    "2025-01-01", "2025-01-05", "2025-01-10", 
    "2025-01-15", "2025-01-20", "2025-01-25",
    "2025-02-01", "2025-02-05", "2025-02-10",
    "2025-02-15",
}).
SetData([]float64{5, 12, 3, 15, 8, 4, 7, 14, 6, 11})

// Optional customization
chart.SetCellSize(15).          // Size of each cell (will adapt to available space)
      SetCellSpacing(3).        // Space between cells
      SetCellRounding(2).       // Corner radius
      SetMaxValue(15).          // Maximum value for color scaling (0 for auto)
      SetDateFormat("2006-01-02") // Go time format string

// GitHub-style green gradient colors (light to dark)
chart.SetColors([]string{
    "#ebedf0", "#9be9a8", "#40c463", "#30a14e", "#216e39",
})

// Render to SVG string
svg := chart.Render()
Heatmap Chart with Positive/Negative Values for Feedback
import (
    "github.com/riclib/gosvgchart"
    "time"
)

// Create a heatmap chart for feedback ratings (-1 to +1)
chart := gosvgchart.NewHeatmapChart().
    SetTitle("User Feedback Ratings").
    SetSize(800, 250)

// Set feedback data with dates in YYYY-MM-DD format
chart.SetLabels([]string{
    "2025-01-01", "2025-01-02", "2025-01-03", 
    "2025-01-04", "2025-01-05", "2025-01-06",
}).
SetData([]float64{0.8, -0.5, 1.0, -0.3, 0.6, -0.9})

// Green gradient for positive feedback
chart.SetColors([]string{
    "#ebedf0", "#9be9a8", "#40c463", "#30a14e", "#216e39",
})

// Red gradient for negative feedback
chart.SetNegativeColors([]string{
    "#ebedf0", "#f9a8a8", "#f67575", "#e64545", "#c92a2a",
})

// Enable support for negative values (enabled by default)
chart.EnableNegativeValues(true)

// Optional: set min value explicitly (default is auto)
chart.SetMinValue(-1.0)

// Optional: set max value explicitly (default is auto) 
chart.SetMaxValue(1.0)

// Render to SVG string
svg := chart.Render()
Heatmap Adaptivity

Heatmaps will automatically:

  1. Use single-letter day labels (S, M, T, W, T, F, S) for each row
  2. Calculate cell sizes based on available space to ensure the entire calendar fits
  3. Adjust to different container sizes while maintaining the calendar structure
// Create a heatmap chart with auto-sizing cells and single-letter day labels
heatmapChart := gosvgchart.NewHeatmapChart().
    SetTitle("Activity Heatmap").
    SetSize(800, 200).  // The cell size will automatically adapt to this space
    SetData(activityData).
    SetStartDate("2023-01-01").
    SetColors([]string{"#ebedf0", "#9be9a8", "#40c463", "#30a14e", "#216e39"})

// The SetCellSize() method is optional - if omitted, cells will be sized to fill available space
// Day labels are automatically set to single letters (S, M, T, W, T, F, S)

svg := heatmapChart.Render()

See cmd/examples/main.go for a working example of adaptive heatmaps with various container sizes.

Markdown Chart Format

For an even simpler way to create charts, especially when working with LLMs or in text environments, you can use the markdown-like format:

Line Chart Example
linechart
title: Monthly Sales
width: 600
height: 400
colors: #3498db, #e74c3c

data:
Jan | 120
Feb | 250
Mar | 180
Apr | 310
May | 270
Jun | 390
Bar Chart Example
barchart
title: Quarterly Revenue
width: 600
height: 400
colors: #2ecc71, #e74c3c, #f39c12, #9b59b6

data:
Q1 | 850
Q2 | 940
Q3 | 1100
Q4 | 1200
Pie Chart Example
piechart
title: Market Share
width: 600
height: 500
colors: #3498db, #2ecc71, #e74c3c, #f39c12, #9b59b6

data:
Product A | 35
Product B | 25
Product C | 20
Product D | 15
Others | 5
Using Auto-Height

You can specify height: auto to automatically calculate the height based on the width:

linechart
title: Revenue with Auto Height
width: 800
height: auto
colors: #3498db

data:
Jan | 120
Feb | 250
Mar | 180
Apr | 310
May | 270
Jun | 390
Heatmap Chart Example
heatmapchart
title: GitHub Contribution Activity
width: 800
height: 200
colors: #ebedf0, #9be9a8, #40c463, #30a14e, #216e39

data:
2025-01-01 | 5
2025-01-03 | 8
2025-01-10 | 3
2025-01-15 | 15
2025-01-24 | 10
2025-02-01 | 7
2025-02-05 | 14
2025-02-15 | 11
2025-02-24 | 10
Feedback Heatmap Example (Positive/Negative Values)
heatmapchart
title: User Feedback Heatmap
width: 800
height: 250
colors: #ebedf0, #9be9a8, #40c463, #30a14e, #216e39
negativecolors: #ebedf0, #f9a8a8, #f67575, #e64545, #c92a2a
supportnegative: true

data:
2025-01-01 | 0.8
2025-01-02 | -0.5
2025-01-03 | 1.0
2025-01-04 | -0.3
2025-01-05 | 0.6
2025-01-06 | -0.9
Side-by-Side Charts Example

You can place multiple charts side by side by using the --- separator within a single code block:

barchart
title: 2023 Revenue
width: 450
height: 300
colors: #3498db, #2ecc71

data:
Q1 | 850
Q2 | 940
Q3 | 1100
Q4 | 1200

---

barchart
title: 2024 Revenue
width: 450
height: 300
colors: #e74c3c, #f39c12

data:
Q1 | 950
Q2 | 1040
Q3 | 1200
Q4 | 1400

Command Line Tools

Convert Markdown to SVG
go run cmd/mdchart/main.go -input chart.md -output chart.svg
Run Web Server
go run cmd/mdchartserver/main.go -port 8080

Then visit:

  • http://localhost:8080 for the web UI
  • POST to http://localhost:8080/chart with markdown content to get SVG
  • GET to http://localhost:8080/charturl?md=linechart_n_title:Test_n_data:_n_A_p_10_n_B_p_20 to get SVG directly via URL

Goldmark Extension

GoSVGChart provides a Goldmark extension that allows you to embed charts directly in your markdown documents:

import (
    "github.com/riclib/gosvgchart/goldmark"
    gm "github.com/yuin/goldmark"
)

// Create a new Goldmark instance with the gosvgchart extension
markdown := gm.New(
    gm.WithExtensions(
        goldmark.New(),
    ),
)

// Convert markdown to HTML with embedded SVG charts
var output []byte
if err := markdown.Convert([]byte(markdownContent), &output); err != nil {
    // Handle error
}

Use the extension in your markdown with fenced code blocks:

```gosvgchart
barchart
title: Quarterly Revenue
width: 600
height: 400
colors: #2ecc71, #e74c3c, #f39c12, #9b59b6

data:
Q1 | 850
Q2 | 940
Q3 | 1100
Q4 | 1200
```

For more details on the Goldmark extension, see the goldmark directory.

Common Methods (Go API)

All chart types share these common methods:

Method Description
SetTitle(title string) Sets the chart title
SetSize(width, height int) Sets the chart dimensions in pixels
SetAutoHeight(auto bool) Enables automatic height calculation based on width (16:9 ratio for standard charts, 250px for heatmaps)
SetData(data []float64) Sets the chart data values
SetLabels(labels []string) Sets the chart labels
SetColors(colors []string) Sets the color palette as hex values (e.g., "#ff0000")
Render() Renders the chart to an SVG string

Chart-Specific Methods (Go API)

Line Chart
Method Description
ShowDataPoints(show bool) Shows or hides data points
SetSmooth(smooth bool) Enables smooth curved lines (when true)
Bar Chart
Method Description
SetHorizontal(horizontal bool) Displays bars horizontally (when true)
SetStacked(stacked bool) Stacks multiple data series (when true)
Pie Chart
Method Description
SetDonutHole(percentage float64) Sets the inner circle size (0-0.9)
Heatmap Chart
Method Description
SetCellSize(size int) Sets the size of each cell in pixels
SetCellSpacing(spacing int) Sets the spacing between cells
SetCellRounding(radius int) Sets the corner radius of cells
SetDateFormat(format string) Sets the date format (Go time format)
SetMaxValue(max float64) Sets the maximum value for color scaling
SetMinValue(min float64) Sets the minimum value for color scaling (useful for negative values)
SetNegativeColors(colors []string) Sets the color palette for negative values (from least to most intense)
EnableNegativeValues(enable bool) Enables or disables support for negative values
SetDayLabels(labels []string) Sets the labels for days of the week
SetMonthLabels(labels []string) Sets the labels for months

Design Philosophy

GoSVGChart was designed with these principles in mind:

  1. Simplicity: The API should be intuitive and require minimal code
  2. Zero Dependencies: Only use the Go standard library
  3. Declarative Syntax: Use method chaining for a clean, readable configuration
  4. LLM-Friendly: Easy to explain to and be used by Large Language Models
  5. Multiple Interfaces: Support both code and text-based chart definitions

Running Examples

GoSVGChart includes several examples to demonstrate different features:

Individual Examples

The examples/ directory contains standalone examples you can run directly:

go run examples/dark_mode_example.go
go run examples/heatmap_autosizing_example.go
go run examples/feedback_heatmap/main.go
Unified Examples Command

The cmd/examples/ directory contains a unified command that can run multiple examples:

# Build the examples command
go build -o chart-examples ./cmd/examples

# Run an example (default is "heatmap")
./chart-examples

# Run a specific example by type
./chart-examples -type heatmap
./chart-examples -type line
./chart-examples -type bar
./chart-examples -type pie

Each example will generate SVG files in the current directory that you can open in a web browser or SVG viewer:

  • Heatmap: heatmap_autosizing.svg and heatmap_autosizing_small.svg
  • Feedback Heatmap: feedback_heatmap.svg
  • Line chart: line_chart_example.svg
  • Bar chart: bar_chart_example.svg
  • Pie chart: pie_chart_example.svg

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BarChart

type BarChart struct {
	BaseChart
	Horizontal bool
	Stacked    bool
}

BarChart implements a bar chart

func NewBarChart

func NewBarChart() *BarChart

NewBarChart creates a new bar chart with default settings

func (*BarChart) AddSeries added in v0.8.0

func (c *BarChart) AddSeries(name string, data []float64) Chart

AddSeries adds a new data series to the bar chart

func (*BarChart) Render

func (c *BarChart) Render() string

Render renders the bar chart to an SVG string

func (*BarChart) SetAutoHeight added in v0.5.0

func (c *BarChart) SetAutoHeight(auto bool) Chart

SetAutoHeight enables automatic height calculation based on width

func (*BarChart) SetColors

func (c *BarChart) SetColors(colors []string) Chart

SetColors sets the color palette as hex values

func (*BarChart) SetData

func (c *BarChart) SetData(data []float64) Chart

SetData sets the chart data values

func (*BarChart) SetHorizontal

func (c *BarChart) SetHorizontal(horizontal bool) *BarChart

SetHorizontal displays bars horizontally

func (*BarChart) SetLabels

func (c *BarChart) SetLabels(labels []string) Chart

SetLabels sets the chart labels

func (*BarChart) SetLegendWidth added in v0.9.0

func (c *BarChart) SetLegendWidth(percentage float64) Chart

SetLegendWidth sets the width of the legend area as a percentage of the chart width

func (*BarChart) SetPalette added in v0.9.3

func (c *BarChart) SetPalette(palette string) Chart

SetPalette sets the color palette mode for automatic color assignment

func (*BarChart) SetSeriesColors added in v0.8.0

func (c *BarChart) SetSeriesColors(colors []string) Chart

SetSeriesColors sets the colors for multiple data series

func (*BarChart) SetSize

func (c *BarChart) SetSize(width, height int) Chart

SetSize sets the chart dimensions in pixels

func (*BarChart) SetStacked

func (c *BarChart) SetStacked(stacked bool) *BarChart

SetStacked stacks multiple data series

func (*BarChart) SetTitle

func (c *BarChart) SetTitle(title string) Chart

SetTitle sets the chart title

type BaseChart

type BaseChart struct {
	ChartType  string
	Title      string
	Width      int
	Height     int
	AutoHeight bool
	Data       []float64
	Labels     []string
	Colors     []string
	// New fields for multiple series support
	Series       []Series
	SeriesColors []string
	ShowTitle    bool
	ShowLegend   bool
	LegendWidth  float64 // Percentage of chart width (0.0-0.5) reserved for legend
	Palette      string  // "auto" or "gradient" for automatic color assignment
	Margin       struct {
		Top    int
		Right  int
		Bottom int
		Left   int
	}
	BackgroundColor string
	DarkModeSupport bool
	DarkTheme       struct {
		BackgroundColor string
		TextColor       string
		AxisColor       string
		GridColor       string
	}
	LightTheme struct {
		BackgroundColor string
		TextColor       string
		AxisColor       string
		GridColor       string
	}
}

BaseChart contains common properties and methods for all chart types

func (*BaseChart) EnableDarkModeSupport added in v0.5.0

func (chart *BaseChart) EnableDarkModeSupport(enable bool) *BaseChart

EnableDarkModeSupport enables automatic adaptation between light and dark mode based on the user's system preferences

func (*BaseChart) SetDarkTheme added in v0.5.0

func (chart *BaseChart) SetDarkTheme(backgroundColor, textColor, axisColor, gridColor string) *BaseChart

SetDarkTheme sets the color scheme for dark mode

func (*BaseChart) SetLegendWidth added in v0.9.0

func (chart *BaseChart) SetLegendWidth(percentage float64) *BaseChart

SetLegendWidth sets the width of the legend area as a percentage of the chart width

func (*BaseChart) SetLightTheme added in v0.5.0

func (chart *BaseChart) SetLightTheme(backgroundColor, textColor, axisColor, gridColor string) *BaseChart

SetLightTheme sets the color scheme for light mode

func (*BaseChart) SetPalette added in v0.9.3

func (chart *BaseChart) SetPalette(palette string) *BaseChart

SetPalette sets the color palette mode for automatic color assignment Valid options are "auto" and "gradient"

type Chart

type Chart interface {
	SetTitle(title string) Chart
	SetSize(width, height int) Chart
	SetAutoHeight(auto bool) Chart
	SetData(data []float64) Chart
	SetLabels(labels []string) Chart
	SetColors(colors []string) Chart
	// New methods for multiple series support
	AddSeries(name string, data []float64) Chart
	SetSeriesColors(colors []string) Chart
	// Layout control
	SetLegendWidth(percentage float64) Chart
	// Color management
	SetPalette(palette string) Chart
	Render() string
}

Chart is the interface that all chart types must implement

type HeatmapChart added in v0.4.0

type HeatmapChart struct {
	BaseChart
	CellSize        int      // Size of each cell in pixels
	CellSpacing     int      // Spacing between cells in pixels
	CellRounding    int      // Corner radius of cells
	DateFormat      string   // Date format string
	DayLabels       []string // Labels for days of week (Sunday-Saturday)
	MonthLabels     []string // Labels for months
	MaxValue        float64  // Maximum value for color scaling (0 for auto)
	MinValue        float64  // Minimum value for color scaling (0 for auto)
	NegativeColors  []string // Colors for negative values (from least to most intense)
	SupportNegative bool     // Whether to support negative values
}

HeatmapChart implements a heatmap chart similar to GitHub's activity heatmap

func NewHeatmapChart added in v0.4.0

func NewHeatmapChart() *HeatmapChart

NewHeatmapChart creates a new heatmap chart with default settings

func (*HeatmapChart) AddSeries added in v0.8.0

func (c *HeatmapChart) AddSeries(name string, data []float64) Chart

AddSeries adds a new data series to the heatmap chart Note: Heatmap charts typically don't support multiple series in the same way as line/bar charts This implementation will replace the existing data with the new series

func (*HeatmapChart) EnableNegativeValues added in v0.10.0

func (c *HeatmapChart) EnableNegativeValues(enable bool) *HeatmapChart

EnableNegativeValues enables or disables negative value support

func (*HeatmapChart) Render added in v0.4.0

func (c *HeatmapChart) Render() string

Render renders the heatmap chart to an SVG string

func (*HeatmapChart) SetAutoHeight added in v0.5.0

func (c *HeatmapChart) SetAutoHeight(auto bool) Chart

SetAutoHeight enables automatic height calculation based on width

func (*HeatmapChart) SetCellRounding added in v0.4.0

func (c *HeatmapChart) SetCellRounding(radius int) *HeatmapChart

SetCellRounding sets the corner radius of cells

func (*HeatmapChart) SetCellSize added in v0.4.0

func (c *HeatmapChart) SetCellSize(size int) *HeatmapChart

SetCellSize sets the size of each cell in pixels

func (*HeatmapChart) SetCellSpacing added in v0.4.0

func (c *HeatmapChart) SetCellSpacing(spacing int) *HeatmapChart

SetCellSpacing sets the spacing between cells in pixels

func (*HeatmapChart) SetColors added in v0.4.0

func (c *HeatmapChart) SetColors(colors []string) Chart

SetColors sets the color palette as hex values (from least to most intense)

func (*HeatmapChart) SetData added in v0.4.0

func (c *HeatmapChart) SetData(data []float64) Chart

SetData sets the chart data values

func (*HeatmapChart) SetDateFormat added in v0.4.0

func (c *HeatmapChart) SetDateFormat(format string) *HeatmapChart

SetDateFormat sets the date format string (Go time format)

func (*HeatmapChart) SetDayLabels added in v0.4.0

func (c *HeatmapChart) SetDayLabels(labels []string) *HeatmapChart

SetDayLabels sets the labels for days of the week Note: This method is deprecated as single-letter day labels are now used by default

func (*HeatmapChart) SetLabels added in v0.4.0

func (c *HeatmapChart) SetLabels(labels []string) Chart

SetLabels sets the chart labels (should be ISO dates: YYYY-MM-DD)

func (*HeatmapChart) SetLegendWidth added in v0.9.0

func (c *HeatmapChart) SetLegendWidth(percentage float64) Chart

SetLegendWidth sets the width of the legend area as a percentage of the chart width

func (*HeatmapChart) SetMaxValue added in v0.4.0

func (c *HeatmapChart) SetMaxValue(max float64) *HeatmapChart

SetMaxValue sets the maximum value for color scaling

func (*HeatmapChart) SetMinValue added in v0.10.0

func (c *HeatmapChart) SetMinValue(min float64) *HeatmapChart

SetMinValue sets the minimum value for color scaling

func (*HeatmapChart) SetMonthLabels added in v0.4.0

func (c *HeatmapChart) SetMonthLabels(labels []string) *HeatmapChart

SetMonthLabels sets the labels for months

func (*HeatmapChart) SetNegativeColors added in v0.10.0

func (c *HeatmapChart) SetNegativeColors(colors []string) *HeatmapChart

SetNegativeColors sets the color palette for negative values (from least to most intense)

func (*HeatmapChart) SetPalette added in v0.9.3

func (c *HeatmapChart) SetPalette(palette string) Chart

SetPalette sets the color palette mode for automatic color assignment

func (*HeatmapChart) SetSeriesColors added in v0.8.0

func (c *HeatmapChart) SetSeriesColors(colors []string) Chart

SetSeriesColors sets the colors for multiple data series For heatmaps, this is the same as SetColors

func (*HeatmapChart) SetSize added in v0.4.0

func (c *HeatmapChart) SetSize(width, height int) Chart

SetSize sets the chart dimensions in pixels

func (*HeatmapChart) SetTitle added in v0.4.0

func (c *HeatmapChart) SetTitle(title string) Chart

SetTitle sets the chart title

type LineChart

type LineChart struct {
	BaseChart
	ShowPoints bool
	Smooth     bool
}

LineChart implements a line chart

func New

func New() *LineChart

New creates a new line chart (for backward compatibility)

func NewLineChart

func NewLineChart() *LineChart

NewLineChart creates a new line chart with default settings

func (*LineChart) AddSeries added in v0.8.0

func (c *LineChart) AddSeries(name string, data []float64) Chart

AddSeries adds a new data series to the line chart

func (*LineChart) Render

func (c *LineChart) Render() string

Render renders the line chart to an SVG string

func (*LineChart) SetAutoHeight added in v0.5.0

func (c *LineChart) SetAutoHeight(auto bool) Chart

SetAutoHeight enables automatic height calculation based on width

func (*LineChart) SetColors

func (c *LineChart) SetColors(colors []string) Chart

SetColors sets the color palette as hex values

func (*LineChart) SetData

func (c *LineChart) SetData(data []float64) Chart

SetData sets the chart data values

func (*LineChart) SetLabels

func (c *LineChart) SetLabels(labels []string) Chart

SetLabels sets the chart labels

func (*LineChart) SetLegendWidth added in v0.9.0

func (c *LineChart) SetLegendWidth(percentage float64) Chart

SetLegendWidth sets the width of the legend area as a percentage of the chart width

func (*LineChart) SetPalette added in v0.9.3

func (c *LineChart) SetPalette(palette string) Chart

SetPalette sets the color palette mode for automatic color assignment

func (*LineChart) SetSeriesColors added in v0.8.0

func (c *LineChart) SetSeriesColors(colors []string) Chart

SetSeriesColors sets the colors for multiple data series

func (*LineChart) SetSize

func (c *LineChart) SetSize(width, height int) Chart

SetSize sets the chart dimensions in pixels

func (*LineChart) SetSmooth

func (c *LineChart) SetSmooth(smooth bool) *LineChart

SetSmooth enables smooth curved lines

func (*LineChart) SetTitle

func (c *LineChart) SetTitle(title string) Chart

SetTitle sets the chart title

func (*LineChart) ShowDataPoints

func (c *LineChart) ShowDataPoints(show bool) *LineChart

ShowDataPoints shows or hides data points for line charts

type PieChart

type PieChart struct {
	BaseChart
	DonutHolePercentage float64
	MaxLabelLength      int  // Maximum label length before truncation
	ShowTooltips        bool // Show tooltips on hover for truncated labels
}

PieChart implements a pie/donut chart

func NewPieChart

func NewPieChart() *PieChart

NewPieChart creates a new pie chart with default settings

func (*PieChart) AddSeries added in v0.8.0

func (c *PieChart) AddSeries(name string, data []float64) Chart

AddSeries adds a new data series to the pie chart Note: Pie charts typically don't support multiple series in the same way as line/bar charts This implementation will replace the existing data with the new series

func (*PieChart) EnableTooltips added in v0.5.1

func (c *PieChart) EnableTooltips(enable bool) *PieChart

EnableTooltips enables or disables tooltips for labels

func (*PieChart) Render

func (c *PieChart) Render() string

Render renders the pie chart to an SVG string

func (*PieChart) SetAutoHeight added in v0.5.0

func (c *PieChart) SetAutoHeight(auto bool) Chart

SetAutoHeight enables automatic height calculation based on width

func (*PieChart) SetColors

func (c *PieChart) SetColors(colors []string) Chart

SetColors sets the color palette as hex values

func (*PieChart) SetData

func (c *PieChart) SetData(data []float64) Chart

SetData sets the chart data values

func (*PieChart) SetDonutHole

func (c *PieChart) SetDonutHole(percentage float64) *PieChart

SetDonutHole sets the inner circle size for donut charts

func (*PieChart) SetLabels

func (c *PieChart) SetLabels(labels []string) Chart

SetLabels sets the chart labels

func (*PieChart) SetLegendWidth added in v0.9.0

func (c *PieChart) SetLegendWidth(percentage float64) Chart

SetLegendWidth sets the width of the legend area as a percentage of the chart width

func (*PieChart) SetMaxLabelLength added in v0.5.1

func (c *PieChart) SetMaxLabelLength(length int) *PieChart

SetMaxLabelLength sets the maximum length for labels before truncation

func (*PieChart) SetPalette added in v0.9.3

func (c *PieChart) SetPalette(palette string) Chart

SetPalette sets the color palette mode for automatic color assignment

func (*PieChart) SetSeriesColors added in v0.8.0

func (c *PieChart) SetSeriesColors(colors []string) Chart

SetSeriesColors sets the colors for multiple data series For pie charts, this is the same as SetColors

func (*PieChart) SetSize

func (c *PieChart) SetSize(width, height int) Chart

SetSize sets the chart dimensions in pixels

func (*PieChart) SetTitle

func (c *PieChart) SetTitle(title string) Chart

SetTitle sets the chart title

type Series added in v0.8.0

type Series struct {
	Name string
	Data []float64
}

Series represents a data series with a name and values

Directories

Path Synopsis
cmd
examples command
mdchart command
mdchartserver command
examples
feedback_heatmap command
Example showing a heatmap with positive and negative values for feedback
Example showing a heatmap with positive and negative values for feedback
multiple_series_example command
Example of multiple series support in GoSVGChart
Example of multiple series support in GoSVGChart
examples command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL