charts

package module
v0.5.23 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: MIT Imports: 18 Imported by: 4

README

go-analyze/charts

license Build Status

Our library focuses on generating beautiful charts and graphs within Go. Graphs are used to show a lot of different types of data, needing to be represented in a unique way in order to convey the meaning behind the data. This Go module attempts to use sophisticated defaults to try and render this data in a simple way, while still offering intuitive options to update the graph rendering as you see fit.

Functionality

Currently supported chart types: line, scatter, bar, horizontal bar, pie, doughnut, radar, heat map, candlestick, funnel and table.

New users should check out the Features Overview on our Wiki to see commonly used features for each chart type, as well as linking to specific examples for the feature.

We also have an extensive catalog of examples. Reference the README within the examples directory to see a list of our example implementations of each chart type and configurations.

Themes

Our library offers a wide range of themes, the examples below are only a small subset of what we offer. See our Themes list in Feature Overview to see our complete theme list.

themes

Line Chart
Line Chart

Line Chart Feature List: https://github.com/go-analyze/charts/wiki/Feature-Overview#line-charts

import (
	"github.com/go-analyze/charts"
)

func main() {
	// values specified where the first index is for each data series or source, and the second index is for each sample.
	values := [][]float64{
		{	// Email
			120, // Mon
			132, // Tue
			101, // Wed
			134, // Thu
			90,  // Fri
			230, // Sat
			210, // Sun
		},
		{
			// values for 'Search Engine' go here
		},
	}
	opt := charts.NewLineChartOptionWithData(values)
	opt.Title = charts.TitleOption{
		Text: "Line Chart Demo",
	}
	opt.XAxis.Labels = []string{
		// The 7 labels here match to the 7 values above
		"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
	}
	opt.Legend = charts.LegendOption{
		SeriesNames: []string{
			"Email", "Search Engine",
		},
	}
	// other options as desired...

	p := charts.NewPainter(charts.PainterOptions{
		Width:        600,
		Height:       400,
	})
	err := p.LineChart(opt)
	// ... err check
	buf, err := p.Bytes()
	// ...

Top Line Chart Examples:

  • line_chart-1-basic - Basic line chart with some simple styling changes and a demonstration of null values.
  • line_chart-2-symbols - Basic line chart which sets a different symbol for each series item.
  • line_chart-3-smooth - Basic line chart with thick smooth lines drawn.
  • line_chart-4-mark - Line chart with included mark points and mark lines.
  • line_chart-6-stacked - Line chart with "Stacked" series enabled, making each series a layer on the chart and the top line showing the sum.
  • line_chart-8-dual_y_axis - Basic line chart with two series, one rendered to the left axis and one to a second y axis on the right.
Scatter Chart
Scatter Chart

Scatter Chart Feature List: https://github.com/go-analyze/charts/wiki/Feature-Overview#scatter-charts

import (
	"github.com/go-analyze/charts"
)

func main() {
	opt := charts.NewScatterChartOptionWithData([][]float64{
		{120, 132, 101, charts.GetNullValue(), 90, 230, 210},
		{ /* values for search engine go here */ },
	})
	opt.Title.Text = "Scatter"
	opt.XAxis.Labels = []string{
		// The 7 labels here match to the 7 values above
		"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
	}
	opt.Legend.SeriesNames = []string{"Email", "Search Engine"}
	// set other field options as desired...

	p := charts.NewPainter(charts.PainterOptions{
		Width:        600,
		Height:       400,
	})
	err := p.ScatterChart(opt)
	// ... err check
	buf, err := p.Bytes()
	// ...

Top Scatter Chart Examples:

Bar Chart
Bar Chart

Bar Chart Feature List: https://github.com/go-analyze/charts/wiki/Feature-Overview#bar-charts

import (
	"github.com/go-analyze/charts"
)

func main() {
	// values specified where the first index is for each data series or source, and the second index is for each sample.
	values := [][]float64{
		{   // Rainfall data
			2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3,
		},
		{
			// 'Evaporation' data goes here
		},
	}
	opt := charts.NewBarChartOptionWithData(values)
	opt.XAxis.Labels = []string{
		// A label for each position in the values above
		"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
	}
	opt.Legend = charts.LegendOption{
		SeriesNames: []string{
			"Rainfall", "Evaporation",
		},
		Offset:       charts.OffsetRight,
	}
	// Example of adding a mark line across the bars, or mark points for specific values
	opt.SeriesList[0].MarkLine.AddLines(charts.SeriesMarkTypeAverage)
	opt.SeriesList[0].MarkPoint.AddPoints(charts.SeriesMarkTypeMax, charts.SeriesMarkTypeMin)
	// other options as desired...

	p := charts.NewPainter(charts.PainterOptions{
		Width:        600,
		Height:       400,
	})
	err := p.BarChart(opt)
	// ... err check
	buf, err := p.Bytes()
	// ...

Top Bar Chart Examples:

Horizontal Bar Chart
Horizontal Bar Chart

Horizontal Bar Chart Feature List: https://github.com/go-analyze/charts/wiki/Feature-Overview#horizontal-bar-charts

Top Horizontal Bar Chart Examples:

Pie Chart
Pie Chart

Pie Chart Feature List: https://github.com/go-analyze/charts/wiki/Feature-Overview#pie-charts

import (
	"github.com/go-analyze/charts"
)

func main() {
	values := []float64{
		1048, // Search Engine
		735,  // Direct
		580,  // Email
		484,  // Union Ads
		300,  // Video Ads
	}
	opt := charts.NewPieChartOptionWithData(values)
	opt.Title = charts.TitleOption{
		Text:             "Pie Chart",
		Offset:           charts.OffsetCenter,
	}
	opt.Legend.SeriesNames = []string{
		"Search Engine", "Direct", "Email", "Union Ads", "Video Ads",
	}
	// other options as desired...

	p := charts.NewPainter(charts.PainterOptions{
		Width:        600,
		Height:       400,
	})
	err := p.PieChart(opt)
	// ... err check
	buf, err := p.Bytes()
	// ...

Top Pie Chart Examples:

  • pie_chart-1-basic - Pie chart with a variety of customization demonstrated including positioning the legend in the bottom right corner.
  • pie_chart-2-radius - Pie chart which varies the series radius by the percentage of the series.
Doughnut Chart
Doughnut Chart

Doughnut Chart Feature List: https://github.com/go-analyze/charts/wiki/Feature-Overview#doughnut-charts

Top Doughnut Chart Examples:

Radar Chart
Radar Chart

Radar Chart Feature List: https://github.com/go-analyze/charts/wiki/Feature-Overview#radar-charts

Top Radar Chart Examples:

Heat Map Chart
Heat Map Chart

Heat Map Chart Feature List: https://github.com/go-analyze/charts/wiki/Feature-Overview#heat-map-charts

Top Heat Map Chart Examples:

Table
Table

Table Feature List: https://github.com/go-analyze/charts/wiki/Feature-Overview#tables

Top Table Examples:

  • table-1 - Table with a variety of table specific configuration and styling demonstrated.
Candlestick Chart
Candlestick Chart

Candlestick Chart Feature List: https://github.com/go-analyze/charts/wiki/Feature-Overview#candlestick-charts

import (
	"github.com/go-analyze/charts"
)

func main() {
	ohlcData := []charts.OHLCData{
		{Open: 100.0, High: 110.0, Low: 95.0, Close: 105.0},
		{Open: 105.0, High: 115.0, Low: 100.0, Close: 112.0},
		{Open: 112.0, High: 118.0, Low: 108.0, Close: 115.0},
		// ... more OHLC data
	}

	opt := charts.NewCandlestickOptionWithData(ohlcData)
	opt.Title.Text = "Candlestick Chart"
	opt.XAxis.Labels = []string{
		"Day 1", "Day 2", "Day 3", // ... matching data points
	}

	p := charts.NewPainter(charts.PainterOptions{
		Width:  800,
		Height: 600,
	})
	err := p.CandlestickChart(opt)
	// ... err check
	buf, err := p.Bytes()
	// ...

Top Candlestick Chart Examples:

Funnel Chart

Funnel Chart Feature List: https://github.com/go-analyze/charts/wiki/Feature-Overview#funnel-charts

import (
	"github.com/go-analyze/charts"
)

func main() {
	values := []float64{
		100, // Show
		80,  // Click
		60,  // Visit
		40,  // Inquiry
		20,  // Order
	}
	opt := charts.NewFunnelChartOptionWithData(values)
	opt.Title.Text = "Funnel Chart"
	opt.Legend.SeriesNames = []string{
		"Show", "Click", "Visit", "Inquiry", "Order",
	}

	p := charts.NewPainter(charts.PainterOptions{
		Width:        600,
		Height:       400,
	})
	err := p.FunnelChart(opt)
	// ... err check
	buf, err := p.Bytes()

Top Funnel Chart Examples:

ECharts Render
import (
	"github.com/go-analyze/charts"
)

func main() {
	buf, err := charts.RenderEChartsToPNG(`{
		"title": {
			"text": "Line Chart"
		},
		"xAxis": {
			"data": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
		},
		"series": [
			{
				"data": [150, 230, 224, 218, 135, 147, 260]
			}
		]
	}`)
	// snip...

Current Project Status

Forked from vicanso/go-charts and the archived wcharczuk/go-chart, our project introduces enhancements for rendering challenging datasets. We aim to build upon their solid foundation to offer a more versatile and user-friendly charting solution.

API Stability

We're committed to refining the API, incorporating feedback and new ideas to enhance flexibility and ease of use.

Until the v1.0.0 release, API changes should be anticipated. We detail needed API changes on our wiki Version Migration Guide.

Changes

Notable improvements in our fork include:

  • Expanded Features: We continue to develop and extend this library. Recent additions include scatter charts with trend lines, a wide range of built-in themes, stacked series, improved support for eCharts configurations, and smooth line rendering.
  • Intuitive Configuration: Our goal is to ensure configuration options are clear and easy to use. In addition to refining the Go API, we have expanded our documentation in both GoDocs and the Wiki.
  • Expanded Testing: We are committed to comprehensive test coverage. Increased test coverage has led to significant bug fixes, ensuring better reliability across a wide range of configurations.

Our library is an evolving project, aiming to become a standout choice for Go developers seeking powerful yet easy-to-use charting tools. We welcome contributions and feedback as we continue to enhance our library's functionality, configurability, and reliability.

wcharczuk/go-chart Changes

If you're migrating from wcharczuk/go-chart, you should be able to migrate with minimal modifications. The wcharczuk/go-chart codebase has been integrated into our chartdraw package. Any necessary changes are documented in our wcharczuk/go‐chart Migration Guide.

Documentation

Index

Constants

View Source
const (
	ChartTypeLine          = "line"
	ChartTypeScatter       = "scatter"
	ChartTypeBar           = "bar"
	ChartTypePie           = "pie"
	ChartTypeDoughnut      = "doughnut"
	ChartTypeRadar         = "radar"
	ChartTypeFunnel        = "funnel"
	ChartTypeHorizontalBar = "horizontalBar"
	ChartTypeHeatMap       = "heatMap"
	ChartTypeCandlestick   = "candlestick"
)
View Source
const (
	ChartOutputSVG = "svg"
	ChartOutputPNG = "png"
	ChartOutputJPG = "jpg"
)
View Source
const (
	PositionLeft   = "left"
	PositionRight  = "right"
	PositionCenter = "center"
	PositionTop    = "top"
	PositionBottom = "bottom"
)
View Source
const (
	AlignLeft   = "left"
	AlignRight  = "right"
	AlignCenter = "center"
)
View Source
const (
	SymbolNone    = "none"
	SymbolCircle  = "circle"
	SymbolDot     = "dot"
	SymbolSquare  = "square"
	SymbolDiamond = "diamond"
)
View Source
const (
	SeriesMarkTypeMax     = "max"
	SeriesMarkTypeMin     = "min"
	SeriesMarkTypeAverage = "average"
)
View Source
const (
	// CandleStyleFilled always fills bodies.
	CandleStyleFilled = "filled"
	// CandleStyleTraditional uses hollow bullish, filled bearish.
	CandleStyleTraditional = "traditional"
	// CandleStyleOutline always outlines only.
	CandleStyleOutline = "outline"
)
View Source
const (
	// ThemeLight is the default theme used, with series colors from echarts.
	ThemeLight = "light"
	// ThemeDark is a dark alternative to the default theme 'light, with series colors from echarts'.
	ThemeDark = "dark"
	// ThemeVividLight is an alternative light theme that has red, yellow, and other bright colors initially in the series.
	// It can be a good option when you want the first few series items to grab the most attention.
	ThemeVividLight = "vivid-light"
	// ThemeVividDark is a dark alternative to 'ThemeVividLight', with the same bright initial series colors.
	ThemeVividDark = "vivid-dark"
	// ThemeGrafana is a grafana styled theme.
	ThemeGrafana = "grafana"
	// ThemeAnt is an ant styled theme.
	ThemeAnt = "ant"
	// ThemeNatureLight provides earthy color tones.
	ThemeNatureLight = "nature-light"
	// ThemeNatureDark provides earthy color tones with a dark background.
	ThemeNatureDark = "nature-dark"
	// ThemeRetro provides colors from the 50's and 60's, silver, maroon, tan, and other vintage colors.
	ThemeRetro = "retro"
	// ThemeOcean is a light colored theme that focuses on shades of green, blue, and other ocean colors.
	ThemeOcean = "ocean"
	// ThemeSlate is a dark theme with a slate background, and light pastel series colors.
	ThemeSlate = "slate"
	// ThemeGray is a light theme that only contains shades of gray.
	ThemeGray = "gray"
	// ThemeWinter is a light theme with shades of white and blue, some light purple.
	ThemeWinter = "winter"
	// ThemeSpring is a light theme with bright greens, yellows, and blues.
	ThemeSpring = "spring"
	// ThemeSummer is a light theme with red, orange, and yellow shades.
	ThemeSummer = "summer"
	// ThemeFall is a dark theme with shades of yellow, orange and brown.
	ThemeFall = "fall"
)
View Source
const (

	// SeriesTrendTypeLinear represents a linear regression trend line that fits a straight line through the data points.
	SeriesTrendTypeLinear = "linear"
	// SeriesTrendTypeCubic represents a cubic polynomial (degree 3) regression trend line that fits a curved line through the data points.
	SeriesTrendTypeCubic = "cubic"
	// Deprecated: SeriesTrendTypeAverage is deprecated, use SeriesTrendTypeSMA instead.
	SeriesTrendTypeAverage = "average"
	// SeriesTrendTypeSMA represents a Simple Moving Average trend line that smooths data using a sliding window average.
	SeriesTrendTypeSMA = "sma"
	// SeriesTrendTypeEMA represents an Exponential Moving Average trend line that gives more weight to recent data points.
	SeriesTrendTypeEMA = "ema"
	// SeriesTrendTypeBollingerUpper represents the upper Bollinger Band (SMA + 2 * standard deviation).
	// Designed for financial time-series analysis to identify volatility boundaries around price movements.
	SeriesTrendTypeBollingerUpper = "bollinger_upper"
	// SeriesTrendTypeBollingerLower represents the lower Bollinger Band (SMA - 2 * standard deviation).
	// Designed for financial time-series analysis to identify volatility boundaries around price movements.
	SeriesTrendTypeBollingerLower = "bollinger_lower"
	// SeriesTrendTypeRSI represents the Relative Strength Index momentum oscillator (0-100 scale).
	// Measures momentum by analyzing sequential price changes, designed for financial time-series analysis.
	SeriesTrendTypeRSI = "rsi"
)
View Source
const FontFamilyNotoSans = "notosans"

FontFamilyNotoSans provides Noto Sans Display Medium, a slightly more condensed Sans variant compared to FontFamilyRoboto. This font offers better internal character and some symbol and emoji support.

View Source
const FontFamilyNotoSansBold = "notosans-bold"

FontFamilyNotoSansBold provides Noto Sans Display Extra Bold, a bold version of FontFamilyNotoSans.

View Source
const FontFamilyRoboto = "roboto"

FontFamilyRoboto is the default chart font (Roboto Medium), it provides a well spaced Sans style font with good latin character support.

Variables

View Source
var (
	// ColorTransparent is a fully transparent color.
	ColorTransparent = drawing.ColorTransparent
	// ColorWhite is R: 255, G: 255, B: 255.
	ColorWhite = drawing.ColorWhite
	// ColorBlack is R: 0, G: 0, B: 0.
	ColorBlack = drawing.ColorBlack
	// ColorGray is R: 128, G: 128, B: 128.
	ColorGray = drawing.ColorGray
	// ColorRed is R: 255, G: 0, B: 0.
	ColorRed = drawing.ColorRed
	// ColorGreen is R: 0, G: 128, B: 0.
	ColorGreen = drawing.ColorGreen
	// ColorBlue is R: 0, G: 0, B: 255.
	ColorBlue = drawing.ColorBlue
	// ColorSilver is R: 192, G: 192, B: 192.
	ColorSilver = drawing.ColorSilver
	// ColorMaroon is R: 128, G: 0, B: 0.
	ColorMaroon = drawing.ColorMaroon
	// ColorPurple is R: 128, G: 0, B: 128.
	ColorPurple = drawing.ColorPurple
	// ColorFuchsia is R: 255, G: 0, B: 255.
	ColorFuchsia = drawing.ColorFuchsia
	// ColorLime is R: 0, G: 255, B: 0.
	ColorLime = drawing.ColorLime
	// ColorOlive is R: 128, G: 128, B: 0.
	ColorOlive = drawing.ColorOlive
	// ColorYellow is R: 255, G: 255, B: 0.
	ColorYellow = drawing.ColorYellow
	// ColorNavy is R: 0, G: 0, B: 128.
	ColorNavy = drawing.ColorNavy
	// ColorTeal is R: 0, G: 128, B: 128.
	ColorTeal = drawing.ColorTeal
	// ColorAqua (or Cyan) is R: 0, G: 255, B: 255.
	ColorAqua = drawing.ColorAqua
	// ColorDarkGray is R: 40, G: 40, B: 40.
	ColorDarkGray = Color{R: 40, G: 40, B: 40, A: 255}
	// ColorLightGray is R: 211, G: 211, B: 211.
	ColorLightGray = drawing.ColorLightGray
	// ColorSlateGray is R: 112, G: 128, B: 144.
	ColorSlateGray = drawing.ColorSlateGray
	// ColorLightSlateGray is R: 119, G: 136, B: 211.
	ColorLightSlateGray = drawing.ColorLightSlateGray
	// ColorAzure is R: 240, G: 255, B: 255.
	ColorAzure = drawing.ColorAzure
	// ColorBeige is R: 245, G: 245, B: 220.
	ColorBeige = drawing.ColorBeige
	// ColorBrown is R: 165, G: 42, B: 42.
	ColorBrown = drawing.ColorBrown
	// ColorChocolate is R: 210, G: 105, B: 30.
	ColorChocolate = drawing.ColorChocolate
	// ColorCoral is R: 255, G: 127, B: 80.
	ColorCoral = drawing.ColorCoral
	// ColorLightCoral is R: 240, G: 128, B: 128.
	ColorLightCoral = drawing.ColorLightCoral
	// ColorGold is R: 255, G: 215, B: 0.
	ColorGold = drawing.ColorGold
	// ColorIndigo is R: 75, G: 0, B: 130.
	ColorIndigo = drawing.ColorIndigo
	// ColorIvory is R: 255, G: 255, B: 250.
	ColorIvory = drawing.ColorIvory
	// ColorOrange is R: 255, G: 165, B: 0.
	ColorOrange = drawing.ColorOrange
	// ColorPink is R: 255, G: 192, B: 203.
	ColorPink = drawing.ColorPink
	// ColorPlum is R: 221, G: 160, B: 221.
	ColorPlum = drawing.ColorPlum
	// ColorSalmon is R: 250, G: 128, B: 114.
	ColorSalmon = drawing.ColorSalmon
	// ColorTan is R: 210, G: 180, B: 140.
	ColorTan = drawing.ColorTan
	// ColorKhaki is R: 240, G: 230, B: 140.
	ColorKhaki = drawing.ColorKhaki
	// ColorTurquoise is R: 64, G: 224, B: 208.
	ColorTurquoise = drawing.ColorTurquoise
	// ColorViolet is R: 238, G: 130, B: 238.
	ColorViolet = drawing.ColorViolet
	// ColorSkyBlue is R: 135, G: 206, B: 235.
	ColorSkyBlue = drawing.ColorSkyBlue
	// ColorLavender is R: 230, G: 230, B: 250.
	ColorLavender = drawing.ColorLavender
	// ColorThistle is R: 216, G: 191, B: 216.
	ColorThistle = drawing.ColorThistle

	// ColorBlackAlt1 is slightly lighter shade of black: R: 51, G: 51, B: 51.
	ColorBlackAlt1 = chartdraw.ColorBlack
	// ColorBlueAlt1 is lighter shade of blue: R:0, G: 116, B: 217.
	ColorBlueAlt1 = chartdraw.ColorBlue
	// ColorBlueAlt2 is a sea blue: R: 106, G: 195, B: 203.
	ColorBlueAlt2 = chartdraw.ColorAlternateBlue
	// ColorBlueAlt3 is the echarts shade of blue: R: 84, G: 112, B: 198.
	ColorBlueAlt3 = Color{R: 84, G: 112, B: 198, A: 255}
	// ColorAquaAlt1 is a lighter aqua: R: 0, G: 217, B: 210.
	ColorAquaAlt1 = chartdraw.ColorCyan
	// ColorAquaAlt2 is the echarts shade of aqua: R: 115, G: 192, B: 222.
	ColorAquaAlt2 = Color{R: 115, G: 192, B: 222, A: 255}
	// ColorSageGreen is a more neutral green, R: 158, G: 188, B: 169.
	ColorSageGreen = Color{R: 156, G: 175, B: 136, A: 255}
	// ColorGreenAlt1 is lighter green: R: 0, G: 217, B: 101.
	ColorGreenAlt1 = chartdraw.ColorGreen
	// ColorGreenAlt2 is R: 42, G: 190, B: 137.
	ColorGreenAlt2 = chartdraw.ColorAlternateGreen
	// ColorGreenAlt3 is darker green: R: 59, G: 162, B: 114.
	ColorGreenAlt3 = Color{R: 59, G: 162, B: 114, A: 255}
	// ColorGreenAlt4 is darker green: R: 80, G: 134, B: 66.
	ColorGreenAlt4 = Color{R: 80, G: 143, B: 66, A: 255}
	// ColorGreenAlt5 is a brighter green: R: 34, G: 197, B: 94.
	ColorGreenAlt5 = Color{R: 34, G: 197, B: 94, A: 255}
	// ColorGreenAlt6 is the echarts shade of green: R: 145, G: 204, B: 117.
	ColorGreenAlt6 = Color{R: 145, G: 204, B: 117, A: 255}
	// ColorGreenAlt7 is natural pale moss green: R: 121, G: 191, B: 127.
	ColorGreenAlt7 = Color{R: 121, G: 191, B: 127, A: 255}
	// ColorPurpleAlt1 is echarts shade of dark purple: R: 154, G: 96, B: 180.
	ColorPurpleAlt1 = Color{R: 154, G: 96, B: 180, A: 255}
	// ColorPurpleAlt2 is echarts shade of light purple: R: 234, G: 124, B: 204.
	ColorPurpleAlt2 = Color{R: 234, G: 124, B: 204, A: 255}
	// ColorRedAlt1 is slightly purple red: R: 217, G: 0, B: 116.
	ColorRedAlt1 = chartdraw.ColorRed
	// ColorRedAlt2 is darker purple red: R: 226, G: 77, B: 66.
	ColorRedAlt2 = Color{R: 226, G: 77, B: 66, A: 255}
	// ColorRedAlt3 is a brighter red: R: 239, G: 68, B: 68.
	ColorRedAlt3 = Color{R: 239, G: 68, B: 68, A: 255}
	// ColorRedAlt4 is the echarts shade of red: R: 238, G: 102, B: 102.
	ColorRedAlt4 = Color{R: 238, G: 102, B: 102, A: 255}
	// ColorOrangeAlt1 is more typical orange: R: 217, G: 101, B: 0.
	ColorOrangeAlt1 = chartdraw.ColorOrange
	// ColorOrangeAlt2 is a lighter orange: R: 250, G: 200, B: 88.
	ColorOrangeAlt2 = Color{R: 250, G: 200, B: 88, A: 255}
	// ColorOrangeAlt3 is a lighter orange: R: 255, G: 152, B: 69.
	ColorOrangeAlt3 = Color{R: 255, G: 152, B: 69, A: 255}
	// ColorOrangeAlt4 is echarts shade of orange: R: 252, G: 132, B: 82.
	ColorOrangeAlt4 = Color{R: 252, G: 132, B: 82, A: 255}
	// ColorYellowAlt1 is a slightly darker yellow: R: 217, G: 210, B: 0.
	ColorYellowAlt1 = chartdraw.ColorYellow
	// ColorMustardYellow is a dark yellow, R: 200, G: 160, B: 60.
	ColorMustardYellow = Color{R: 200, G: 160, B: 60, A: 255}
	// ColorDesertSand is a very light yellow / tan, R: 226, G: 201, B: 175.
	ColorDesertSand = Color{R: 226, G: 201, B: 175, A: 255}
)
View Source
var (
	// LabelFormatterValueShort provides a short value with at most 2 decimal places.
	LabelFormatterValueShort = func(index int, name string, val float64) (string, *LabelStyle) {
		return defaultValueFormatter(val), nil
	}

	// LabelFormatterNameShortValue puts the series name next to the value with up to 2 decimal places.
	LabelFormatterNameShortValue = func(index int, name string, val float64) (string, *LabelStyle) {
		return name + ": " + defaultValueFormatter(val), nil
	}
)
View Source
var BoxZero = chartdraw.BoxZero

BoxZero is an unset Box with no dimensions.

View Source
var OffsetCenter = OffsetStr{Left: PositionCenter}

OffsetCenter positions a component in the center.

View Source
var OffsetLeft = OffsetStr{Left: PositionLeft}

OffsetLeft positions a component on the left.

View Source
var OffsetRight = OffsetStr{Left: PositionRight}

OffsetRight positions a component on the right.

Functions

func DegreesToRadians added in v0.4.1

func DegreesToRadians(degrees float64) float64

DegreesToRadians returns degrees as radians.

func FormatValueHumanize added in v0.3.1

func FormatValueHumanize(value float64, decimals int, ensureTrailingZeros bool) string

FormatValueHumanize formats a value with specified precision and comma separators.

func FormatValueHumanizeShort added in v0.3.1

func FormatValueHumanizeShort(value float64, decimals int, ensureTrailingZeros bool) string

FormatValueHumanizeShort formats a value with specified precision and comma separators. Values over 1,000 are shortened with k, M, G, T suffixes.

func GetDefaultFont

func GetDefaultFont() *truetype.Font

GetDefaultFont returns the default font.

func GetFont

func GetFont(fontFamily string) *truetype.Font

GetFont returns the font by family name, or the default if the family is not installed.

func GetNullValue

func GetNullValue() float64

GetNullValue returns the null value for setting series points with "no" or "unknown" value.

func InstallFont

func InstallFont(fontFamily string, data []byte) error

InstallFont installs a font for chart rendering.

func InstallTheme

func InstallTheme(name string, opt ThemeOption)

InstallTheme adds a theme to the catalog for later retrieval using GetTheme.

func IntSliceToFloat64 added in v0.5.0

func IntSliceToFloat64(slice []int) []float64

IntSliceToFloat64 converts an int slice to a float64 slice for use in charts.

func Ptr added in v0.5.0

func Ptr[T any](val T) *T

Ptr is a helper function for building config options that reference pointers.

func RadiansToDegrees added in v0.4.1

func RadiansToDegrees(value float64) float64

RadiansToDegrees translates a radian value to a degree value.

func RenderEChartsToJPG added in v0.5.1

func RenderEChartsToJPG(options string) ([]byte, error)

RenderEChartsToJPG renders an ECharts option JSON string to JPG bytes.

func RenderEChartsToPNG

func RenderEChartsToPNG(options string) ([]byte, error)

RenderEChartsToPNG renders an ECharts option JSON string to PNG bytes.

func RenderEChartsToSVG

func RenderEChartsToSVG(options string) ([]byte, error)

RenderEChartsToSVG renders an ECharts option JSON string to SVG bytes.

func SetDefaultChartDimensions added in v0.4.0

func SetDefaultChartDimensions(width, height int)

SetDefaultChartDimensions sets the default chart width and height when not otherwise specified in their configuration.

func SetDefaultFont

func SetDefaultFont(fontFamily string) error

SetDefaultFont sets the default font by name.

func SetDefaultTheme

func SetDefaultTheme(name string) error

SetDefaultTheme sets the default theme by name.

func SliceToFloat64 added in v0.5.0

func SliceToFloat64[T any](slice []T, conversion func(T) float64) []float64

SliceToFloat64 converts a slice of arbitrary types to float64 using the provided conversion function.

Types

type BarChartOption

type BarChartOption struct {
	// Theme specifies the colors used for the bar chart.
	Theme ColorPalette
	// Padding specifies the padding around the chart.
	Padding Box
	// Deprecated: Font is deprecated, instead the font needs to be set on the SeriesLabel, or other specific elements.
	Font *truetype.Font
	// SeriesList provides the data population for the chart. Typically constructed using NewSeriesListBar.
	SeriesList BarSeriesList
	// StackSeries when *true renders series stacked within one bar.
	// This ignores some options including BarMargin and SeriesLabelPosition.
	// MarkLine only renders for the first series and stacking only applies to the first y-axis.
	StackSeries *bool
	// SeriesLabelPosition specifies the label position for the series: "top" or "bottom".
	SeriesLabelPosition string
	// XAxis contains options for the x-axis.
	XAxis XAxisOption
	// YAxis contains options for the y-axis. At most two y-axes are supported.
	YAxis []YAxisOption
	// Title contains options for rendering the chart title.
	Title TitleOption
	// Legend contains options for the data legend.
	Legend LegendOption
	// BarWidth specifies the width of each bar. May be reduced to fit all series on the chart.
	BarWidth int // TODO - v0.6 - Update to float64 to represent a precent
	// BarMargin specifies the margin between grouped bars. BarWidth takes priority over a set margin.
	BarMargin *float64 // TODO - v0.6 - Update to be percent based
	// RoundedBarCaps when *true draws bars with rounded top corners.
	RoundedBarCaps *bool
	// ValueFormatter defines how float values are rendered to strings, notably for numeric axis labels.
	ValueFormatter ValueFormatter
}

BarChartOption defines the options for rendering a bar chart. Render the chart using Painter.BarChart.

func NewBarChartOptionWithData added in v0.4.0

func NewBarChartOptionWithData(data [][]float64) BarChartOption

NewBarChartOptionWithData returns an initialized BarChartOption with the SeriesList set with the provided data slice.

func NewBarChartOptionWithSeries added in v0.5.9

func NewBarChartOptionWithSeries(sl BarSeriesList) BarChartOption

NewBarChartOptionWithSeries returns an initialized BarChartOption with the provided SeriesList.

type BarSeries added in v0.5.0

type BarSeries struct {
	// Values provides the series data values.
	Values []float64
	// YAxisIndex is the index for the axis, it must be 0 or 1.
	YAxisIndex int
	// Label provides the series labels.
	Label SeriesLabel
	// Name specifies a name for the series.
	Name string
	// MarkPoint provides a configuration for mark points for this series. If Label is also enabled, the MarkPoint
	// will replace the label where rendered.
	MarkPoint SeriesMarkPoint
	// MarkLine provides a configuration for mark lines for this series. When using a MarkLine, you will want to
	// configure padding to the chart on the right for the values.
	MarkLine SeriesMarkLine
	// contains filtered or unexported fields
}

BarSeries references a population of data for bar charts.

func (*BarSeries) Summary added in v0.5.0

func (b *BarSeries) Summary() populationSummary

type BarSeriesList added in v0.5.0

type BarSeriesList []BarSeries

BarSeriesList provides the data populations for bar charts (BarChartOption).

func NewSeriesListBar added in v0.4.0

func NewSeriesListBar(values [][]float64, opts ...BarSeriesOption) BarSeriesList

NewSeriesListBar builds a SeriesList for a bar chart. The first dimension of the values indicates the population of the data, while the second dimension provides the samples for the population (on the X-Axis).

func (BarSeriesList) SetSeriesLabels added in v0.5.6

func (b BarSeriesList) SetSeriesLabels(label SeriesLabel)

SetSeriesLabels sets the label for all elements in the series.

func (BarSeriesList) SumSeries added in v0.5.0

func (b BarSeriesList) SumSeries() []float64

SumSeries returns a float64 slice with the sum of each series.

func (BarSeriesList) SumSeriesValues added in v0.5.0

func (b BarSeriesList) SumSeriesValues() []float64

SumSeriesValues returns a float64 slice with each series totaled by the value index.

func (BarSeriesList) ToGenericSeriesList added in v0.5.0

func (b BarSeriesList) ToGenericSeriesList() GenericSeriesList

type BarSeriesOption added in v0.4.0

type BarSeriesOption struct {
	Label     SeriesLabel
	Names     []string
	MarkPoint SeriesMarkPoint
	MarkLine  SeriesMarkLine
}

BarSeriesOption provides series customization for NewSeriesListBar or NewSeriesListHorizontalBar.

type Box

type Box = chartdraw.Box

Box defines spacing boundaries around a component.

func NewBox added in v0.4.6

func NewBox(left, top, right, bottom int) Box

NewBox returns a new Box with the specified left, top, right, and bottom values to define the position and dimensions.

func NewBoxEqual added in v0.4.6

func NewBoxEqual(size int) Box

NewBoxEqual returns a new box with equal sizes to each side.

type CandlestickChartOption added in v0.5.17

type CandlestickChartOption struct {
	// Theme specifies the colors used for the candlestick chart.
	Theme ColorPalette
	// Padding specifies the padding around the chart.
	Padding Box
	// SeriesList provides the OHLC data population for the chart. Typically constructed using NewSeriesListCandlestick.
	SeriesList CandlestickSeriesList
	// XAxis contains options for the x-axis.
	XAxis XAxisOption
	// YAxis contains options for the y-axis. At most two y-axes are supported.
	YAxis []YAxisOption
	// Title contains options for rendering the chart title.
	Title TitleOption
	// Legend contains options for the data legend.
	Legend LegendOption
	// CandleWidth sets body width ratio (0.0–1.0, default 0.8).
	CandleWidth float64
	// ShowWicks controls whether high-low wicks are displayed by default. When nil, wicks are shown.
	// Individual series can override this setting.
	ShowWicks *bool
	// WickWidth sets wick stroke width in pixels (default 1.0).
	WickWidth float64
	// CandleMargin sets inter-series spacing ratio (0.0–1.0, auto by default).
	// Only applies with multiple candlestick series.
	CandleMargin *float64
	// ValueFormatter formats numeric values.
	ValueFormatter ValueFormatter
}

CandlestickChartOption defines options for rendering candlestick charts. Render the chart using Painter.CandlestickChart.

func NewCandlestickOptionWithData added in v0.5.17

func NewCandlestickOptionWithData(data ...[]OHLCData) CandlestickChartOption

NewCandlestickOptionWithData creates a CandlestickChartOption from OHLC data slices.

func NewCandlestickOptionWithSeries added in v0.5.17

func NewCandlestickOptionWithSeries(series ...CandlestickSeries) CandlestickChartOption

NewCandlestickOptionWithSeries returns an initialized CandlestickChartOption with the provided Series.

type CandlestickPatternConfig added in v0.5.17

type CandlestickPatternConfig struct {
	// PreferPatternLabels controls pattern/user label precedence
	// true = pattern labels have priority over user labels, false = user labels have priority over pattern labels
	PreferPatternLabels bool

	// PatternFormatter allows custom formatting, if nil, uses default formatting with theme colors.
	PatternFormatter PatternFormatter

	// EnabledPatterns lists specific patterns to detect
	// nil or empty = no patterns detected (PatternConfig must be set to enable)
	// Use With* methods to configure patterns
	EnabledPatterns []string

	// DojiThreshold is the body-to-range ratio threshold for doji pattern detection.
	// Default: 0.05 (5% - standard textbook definition)
	// A candlestick where the body is ≤5% of the total range is considered a doji.
	DojiThreshold float64

	// ShadowTolerance is the shadow-to-range ratio threshold for patterns requiring minimal shadows.
	// Used by marubozu patterns to determine acceptable shadow size.
	// Default: 0.01 (1% of range)
	ShadowTolerance float64

	// ShadowRatio is the minimum shadow-to-body ratio for patterns requiring long shadows.
	// Used by hammer, shooting star, and similar patterns.
	// Default: 2.0 (shadow must be at least 2x the body - standard textbook definition)
	ShadowRatio float64

	// EngulfingMinSize is the minimum size ratio for engulfing patterns.
	// The engulfing candle body must be at least this percentage of the engulfed candle body.
	// Default: 1.0 (100% - must completely engulf the previous body)
	EngulfingMinSize float64
}

CandlestickPatternConfig configures automatic pattern detection. EXPERIMENTAL: Pattern detection logic is under active development and may change in future versions.

func (*CandlestickPatternConfig) MergePatterns added in v0.5.17

MergePatterns creates a new CandlestickPatternConfig by combining the enabled patterns config with another. It returns a union of both pattern sets with the current config taking precedence for other settings.

func (*CandlestickPatternConfig) WithDarkCloudCover added in v0.5.17

func (c *CandlestickPatternConfig) WithDarkCloudCover() *CandlestickPatternConfig

WithDarkCloudCover adds the dark cloud cover pattern.

func (*CandlestickPatternConfig) WithDoji added in v0.5.17

WithDoji adds the doji pattern.

func (*CandlestickPatternConfig) WithDojiThreshold added in v0.5.17

func (c *CandlestickPatternConfig) WithDojiThreshold(threshold float64) *CandlestickPatternConfig

WithDojiThreshold sets the doji threshold (default: 0.05).

func (*CandlestickPatternConfig) WithDragonfly added in v0.5.17

WithDragonfly adds the dragonfly doji pattern.

func (*CandlestickPatternConfig) WithEngulfingBear added in v0.5.17

func (c *CandlestickPatternConfig) WithEngulfingBear() *CandlestickPatternConfig

WithEngulfingBear adds the bearish engulfing pattern.

func (*CandlestickPatternConfig) WithEngulfingBull added in v0.5.17

func (c *CandlestickPatternConfig) WithEngulfingBull() *CandlestickPatternConfig

WithEngulfingBull adds the bullish engulfing pattern.

func (*CandlestickPatternConfig) WithEngulfingMinSize added in v0.5.17

func (c *CandlestickPatternConfig) WithEngulfingMinSize(size float64) *CandlestickPatternConfig

WithEngulfingMinSize sets the engulfing minimum size (default: 1.0).

func (*CandlestickPatternConfig) WithEveningStar added in v0.5.17

func (c *CandlestickPatternConfig) WithEveningStar() *CandlestickPatternConfig

WithEveningStar adds the evening star pattern.

func (*CandlestickPatternConfig) WithGravestone added in v0.5.17

WithGravestone adds the gravestone doji pattern.

func (*CandlestickPatternConfig) WithHammer added in v0.5.17

WithHammer adds the hammer pattern.

func (*CandlestickPatternConfig) WithInvertedHammer added in v0.5.17

func (c *CandlestickPatternConfig) WithInvertedHammer() *CandlestickPatternConfig

WithInvertedHammer adds the inverted hammer pattern.

func (*CandlestickPatternConfig) WithMarubozuBear added in v0.5.17

func (c *CandlestickPatternConfig) WithMarubozuBear() *CandlestickPatternConfig

WithMarubozuBear adds the bearish marubozu pattern.

func (*CandlestickPatternConfig) WithMarubozuBull added in v0.5.17

func (c *CandlestickPatternConfig) WithMarubozuBull() *CandlestickPatternConfig

WithMarubozuBull adds the bullish marubozu pattern.

func (*CandlestickPatternConfig) WithMorningStar added in v0.5.17

func (c *CandlestickPatternConfig) WithMorningStar() *CandlestickPatternConfig

WithMorningStar adds the morning star pattern.

func (*CandlestickPatternConfig) WithPatternFormatter added in v0.5.17

func (c *CandlestickPatternConfig) WithPatternFormatter(formatter PatternFormatter) *CandlestickPatternConfig

WithPatternFormatter sets a custom pattern formatter.

func (*CandlestickPatternConfig) WithPatternsAll added in v0.5.17

func (c *CandlestickPatternConfig) WithPatternsAll() *CandlestickPatternConfig

WithPatternsAll enables all standard patterns.

func (*CandlestickPatternConfig) WithPatternsBearish added in v0.5.17

func (c *CandlestickPatternConfig) WithPatternsBearish() *CandlestickPatternConfig

WithPatternsBearish enables only bearish patterns.

func (*CandlestickPatternConfig) WithPatternsBullish added in v0.5.17

func (c *CandlestickPatternConfig) WithPatternsBullish() *CandlestickPatternConfig

WithPatternsBullish enables only bullish patterns.

func (*CandlestickPatternConfig) WithPatternsCore added in v0.5.17

func (c *CandlestickPatternConfig) WithPatternsCore() *CandlestickPatternConfig

WithPatternsCore enables only the most reliable patterns that work well without volume.

func (*CandlestickPatternConfig) WithPatternsReversal added in v0.5.17

func (c *CandlestickPatternConfig) WithPatternsReversal() *CandlestickPatternConfig

WithPatternsReversal enables only reversal patterns.

func (*CandlestickPatternConfig) WithPatternsTrend added in v0.5.17

func (c *CandlestickPatternConfig) WithPatternsTrend() *CandlestickPatternConfig

WithPatternsTrend enables only trend continuation patterns.

func (*CandlestickPatternConfig) WithPiercingLine added in v0.5.17

func (c *CandlestickPatternConfig) WithPiercingLine() *CandlestickPatternConfig

WithPiercingLine adds the piercing line pattern.

func (*CandlestickPatternConfig) WithPreferPatternLabels added in v0.5.17

func (c *CandlestickPatternConfig) WithPreferPatternLabels(prefer bool) *CandlestickPatternConfig

WithPreferPatternLabels sets whether pattern labels have priority over user labels.

func (*CandlestickPatternConfig) WithShadowRatio added in v0.5.17

func (c *CandlestickPatternConfig) WithShadowRatio(ratio float64) *CandlestickPatternConfig

WithShadowRatio sets the shadow ratio (default: 2.0).

func (*CandlestickPatternConfig) WithShadowTolerance added in v0.5.17

func (c *CandlestickPatternConfig) WithShadowTolerance(tolerance float64) *CandlestickPatternConfig

WithShadowTolerance sets the shadow tolerance (default: 0.01).

func (*CandlestickPatternConfig) WithShootingStar added in v0.5.17

func (c *CandlestickPatternConfig) WithShootingStar() *CandlestickPatternConfig

WithShootingStar adds the shooting star pattern.

type CandlestickSeries added in v0.5.17

type CandlestickSeries struct {
	// Data provides OHLC data for each time period.
	Data []OHLCData
	// YAxisIndex is the index for the axis, it must be 0 or 1.
	YAxisIndex int
	// Label provides the series labels.
	Label SeriesLabel
	// Name specifies a name for the series.
	Name string

	// OpenMarkPoint provides mark points for open values.
	OpenMarkPoint SeriesMarkPoint
	// OpenMarkLine provides mark lines for open values.
	OpenMarkLine SeriesMarkLine
	// OpenTrendLine provides trend lines for open values.
	OpenTrendLine []SeriesTrendLine
	// HighMarkPoint provides mark points for high values.
	HighMarkPoint SeriesMarkPoint
	// HighMarkLine provides mark lines for high values.
	HighMarkLine SeriesMarkLine
	// HighTrendLine provides trend lines for high values.
	HighTrendLine []SeriesTrendLine
	// LowMarkPoint provides mark points for low values.
	LowMarkPoint SeriesMarkPoint
	// LowMarkLine provides mark lines for low values.
	LowMarkLine SeriesMarkLine
	// LowTrendLine provides trend lines for low values.
	LowTrendLine []SeriesTrendLine
	// CloseMarkPoint provides mark points for close values.
	CloseMarkPoint SeriesMarkPoint
	// CloseMarkLine provides mark lines for close values.
	CloseMarkLine SeriesMarkLine
	// CloseTrendLine provides trend lines for close values.
	CloseTrendLine []SeriesTrendLine

	// ShowWicks hides wicks when false (body only). Overrides chart-level setting.
	ShowWicks *bool
	// CandleStyle specifies the visual style: CandleStyleFilled, CandleStyleTraditional, or CandleStyleOutline.
	CandleStyle string
	// PatternConfig configures automatic pattern detection and labeling.
	PatternConfig *CandlestickPatternConfig
	// contains filtered or unexported fields
}

CandlestickSeries references OHLC data for candlestick charts.

func AggregateCandlestick added in v0.5.17

func AggregateCandlestick(data CandlestickSeries, factor int) CandlestickSeries

AggregateCandlestick aggregates OHLC data by the specified factor.

func (*CandlestickSeries) ExtractClosePrices added in v0.5.17

func (k *CandlestickSeries) ExtractClosePrices() []float64

ExtractClosePrices extracts close prices from OHLC data for use with indicators.

func (*CandlestickSeries) ExtractHighPrices added in v0.5.17

func (k *CandlestickSeries) ExtractHighPrices() []float64

ExtractHighPrices extracts high prices from OHLC data.

func (*CandlestickSeries) ExtractLowPrices added in v0.5.17

func (k *CandlestickSeries) ExtractLowPrices() []float64

ExtractLowPrices extracts low prices from OHLC data.

func (*CandlestickSeries) ExtractOpenPrices added in v0.5.17

func (k *CandlestickSeries) ExtractOpenPrices() []float64

ExtractOpenPrices extracts open prices from OHLC data.

func (*CandlestickSeries) Summary added in v0.5.17

func (k *CandlestickSeries) Summary() populationSummary

type CandlestickSeriesList added in v0.5.17

type CandlestickSeriesList []CandlestickSeries

CandlestickSeriesList holds multiple CandlestickSeries values.

func NewSeriesListCandlestick added in v0.5.17

func NewSeriesListCandlestick(data [][]OHLCData, opts ...CandlestickSeriesOption) CandlestickSeriesList

NewSeriesListCandlestick builds a SeriesList for candlestick charts from OHLC data.

func (CandlestickSeriesList) SetSeriesLabels added in v0.5.17

func (k CandlestickSeriesList) SetSeriesLabels(label SeriesLabel)

SetSeriesLabels sets the label for all elements in the series.

func (CandlestickSeriesList) SumSeries added in v0.5.17

func (k CandlestickSeriesList) SumSeries() []float64

SumSeries returns a float64 slice with the sum of each series. For candlestick series, this sums the High and Low values (used for range calculations).

func (CandlestickSeriesList) ToGenericSeriesList added in v0.5.17

func (k CandlestickSeriesList) ToGenericSeriesList() GenericSeriesList

ToGenericSeriesList converts candlestick series to generic series format. Each candlestick is encoded as 4 consecutive float64 values: [Open, High, Low, Close]. Invalid OHLC data is encoded with null values to maintain the 4-element structure.

type CandlestickSeriesOption added in v0.5.17

type CandlestickSeriesOption struct {
	// Label styles the series labels.
	Label SeriesLabel
	// Names provide data names for each series.
	Names []string
	// OpenMarkPoint marks open prices.
	OpenMarkPoint SeriesMarkPoint
	// OpenMarkLine draws reference lines for open prices.
	OpenMarkLine SeriesMarkLine
	// OpenTrendLine adds trend lines based on opens.
	OpenTrendLine []SeriesTrendLine
	// HighMarkPoint marks high prices.
	HighMarkPoint SeriesMarkPoint
	// HighMarkLine draws reference lines for highs.
	HighMarkLine SeriesMarkLine
	// HighTrendLine adds trend lines based on highs.
	HighTrendLine []SeriesTrendLine
	// LowMarkPoint marks low prices.
	LowMarkPoint SeriesMarkPoint
	// LowMarkLine draws reference lines for lows.
	LowMarkLine SeriesMarkLine
	// LowTrendLine adds trend lines based on lows.
	LowTrendLine []SeriesTrendLine
	// CloseMarkPoint marks closing prices.
	CloseMarkPoint SeriesMarkPoint
	// CloseMarkLine draws reference lines for closes.
	CloseMarkLine SeriesMarkLine
	// CloseTrendLine adds trend lines based on closes.
	CloseTrendLine []SeriesTrendLine
	// CandleStyle sets the drawing style for candles.
	CandleStyle string
	// PatternConfig configures candlestick pattern detection.
	PatternConfig *CandlestickPatternConfig
}

CandlestickSeriesOption configures optional elements when building candlestick series.

type ChartOption

type ChartOption struct {
	// OutputFormat specifies the output type of chart: "svg", "png", or "jpg". Default is "png".
	OutputFormat string
	// Width is the width of the chart.
	Width int
	// Height is the height of the chart.
	Height int
	// Theme specifies the colors used for the chart. Built in themes can be loaded using GetTheme with
	// "light", "dark", "vivid-light", "vivid-dark", "ant" or "grafana".
	Theme ColorPalette
	// Padding specifies the padding for the chart. Default is [20, 20, 20, 20].
	Padding Box
	// XAxis contains options for the x-axis.
	XAxis XAxisOption
	// YAxis contains options for the y-axis. At most two y-axes are supported.
	YAxis []YAxisOption
	// Title contains options for rendering the chart title.
	Title TitleOption
	// Legend contains options for the data legend.
	Legend LegendOption
	// Deprecated: Font is deprecated, instead the font needs to be set on the SeriesLabel, or other specific elements.
	Font *truetype.Font
	// Box specifies the drawing area for the chart.
	Box Box
	// SeriesList provides the population data for the chart, constructed through NewSeriesListGeneric.
	SeriesList GenericSeriesList
	// StackSeries when set to *true causes series to be layered or stacked.
	// This significantly changes chart visualization; see specific chart godocs for details.
	StackSeries *bool
	// RadarIndicators is the list of radar indicators for radar charts.
	RadarIndicators []RadarIndicator
	// Symbol specifies the symbol to draw at data points. Empty (default) varies by chart type.
	// Specify 'none' to enforce no symbol, or specify a desired symbol: 'circle', 'dot', 'square', 'diamond'.
	Symbol Symbol // TODO - v0.6 - consider combining symbol with size into a SymbolStyle struct
	// LineStrokeWidth is the stroke width for line charts.
	LineStrokeWidth float64
	// FillArea when set to *true fills the area under the line in line charts.
	FillArea *bool
	// FillOpacity is the opacity or alpha channel (0-255) of the area fill in line charts.
	FillOpacity uint8
	// Deprecated: BarWidth is deprecated, instead use BarSize.
	BarWidth int
	// Deprecated: BarHeight is deprecated, instead use BarSize.
	BarHeight int
	// BarSize represents the width of bars, or height for horizontal bar charts.
	BarSize int
	// BarMargin specifies the margin between grouped bars. BarSize takes priority over margin.
	BarMargin *float64
	// Radius is the target radius for pie and radar charts. Default is "40%".
	Radius string
	// Children are child charts to render together.
	Children []ChartOption

	// ValueFormatter formats numeric values into labels.
	ValueFormatter ValueFormatter
	// contains filtered or unexported fields
}

ChartOption represents a generic method of representing a chart. This can be useful when you want to render different chart types with the same data and configuration.

type Color

type Color = drawing.Color

Color represents an RGBA color.

func ColorConvertGo added in v0.4.4

func ColorConvertGo(c color.RGBA) Color

ColorConvertGo converts Go's built-in colors to our Color struct. Allows easy use of colors defined in image/colornames.

func ColorFromHex added in v0.4.4

func ColorFromHex(hex string) Color

ColorFromHex returns a color from a CSS hex code. Trims a leading '#' character if present.

func ColorFromKnown added in v0.4.4

func ColorFromKnown(known string) Color

ColorFromKnown returns an internal color from a known (basic) color name.

func ColorFromRGBA added in v0.4.4

func ColorFromRGBA(color string) Color

ColorFromRGBA returns a color from CSS 'rgb(i,i,i)' or 'rgba(i,i,i,f)' format.

func ColorRGB added in v0.4.4

func ColorRGB(r, g, b uint8) Color

ColorRGB constructs a fully opaque color with the specified RGB values.

func ParseColor added in v0.3.2

func ParseColor(rawColor string) Color

ParseColor parses a color from a string. Supports hex with '#' prefix (e.g. '#313233'), rgb(i,i,i) or rgba(i,i,i,f) format, or common names (e.g. 'red').

type ColorPalette

type ColorPalette interface {
	IsDark() bool
	GetXAxisStrokeColor() Color
	GetYAxisStrokeColor() Color
	GetAxisSplitLineColor() Color
	GetSeriesColor(int) Color
	GetSeriesTrendColor(int) Color
	GetBackgroundColor() Color
	GetTitleTextColor() Color
	GetMarkTextColor() Color
	GetLabelTextColor() Color
	GetLegendTextColor() Color
	GetXAxisTextColor() Color
	GetYAxisTextColor() Color
	GetTitleBorderColor() Color
	GetLegendBorderColor() Color
	// WithXAxisColor returns a new ColorPalette with the specified x-axis color.
	// Use WithXAxisTextColor to adjust the text color.
	WithXAxisColor(Color) ColorPalette
	// WithYAxisColor returns a new ColorPalette with the specified y-axis color.
	// Use WithYAxisTextColor to adjust the text color.
	WithYAxisColor(Color) ColorPalette
	// WithYAxisSeriesColor returns a new ColorPalette using the specified series color for y-axis and values.
	WithYAxisSeriesColor(int) ColorPalette
	// WithTitleTextColor returns a new ColorPalette with the specified title text color.
	WithTitleTextColor(Color) ColorPalette
	// WithMarkTextColor returns a new ColorPalette with the specified mark point and line label color.
	WithMarkTextColor(Color) ColorPalette
	// WithLabelTextColor returns a new ColorPalette with the specified value label color.
	WithLabelTextColor(Color) ColorPalette
	// WithLegendTextColor returns a new ColorPalette with the specified legend text color.
	WithLegendTextColor(Color) ColorPalette
	// WithXAxisTextColor returns a new ColorPalette with the specified x-axis label color.
	WithXAxisTextColor(Color) ColorPalette
	// WithYAxisTextColor returns a new ColorPalette with the specified y-axis label color.
	WithYAxisTextColor(Color) ColorPalette
	// WithSeriesColors returns a new ColorPalette with the specified series colors.
	// Trend line colors default to match series colors. Use WithSeriesTrendColors for further customization.
	WithSeriesColors([]Color) ColorPalette
	// WithSeriesTrendColors returns a new ColorPalette with the specified trend line colors.
	WithSeriesTrendColors([]Color) ColorPalette
	// WithBackgroundColor returns a new ColorPalette with the specified background color.
	WithBackgroundColor(Color) ColorPalette
	// WithTitleBorderColor returns a new ColorPalette with the specified title border color.
	WithTitleBorderColor(Color) ColorPalette
	// WithLegendBorderColor returns a new ColorPalette with the specified legend border color.
	WithLegendBorderColor(Color) ColorPalette
	// GetCandleWickColor returns the color for the high-low wicks.
	GetCandleWickColor() Color
	// GetSeriesUpDownColors returns distinct "up" and "down" colors for each series index.
	GetSeriesUpDownColors(index int) (Color, Color)
}

ColorPalette provides the theming for the chart.

func GetDefaultTheme

func GetDefaultTheme() ColorPalette

GetDefaultTheme returns the default theme.

func GetTheme

func GetTheme(name string) ColorPalette

GetTheme returns an installed theme by name, or the default if not found.

func MakeTheme

func MakeTheme(opt ThemeOption) ColorPalette

MakeTheme constructs a theme without installing it into the catalog.

type DoughnutChartOption added in v0.5.6

type DoughnutChartOption struct {
	// Theme specifies the colors used for the doughnut chart.
	Theme ColorPalette
	// Padding specifies the padding around the chart.
	Padding Box
	// SeriesList provides the data population for the chart. Typically constructed using NewSeriesListDoughnut.
	SeriesList DoughnutSeriesList
	// Title contains options for rendering the chart title.
	Title TitleOption
	// Legend contains options for the data legend.
	Legend LegendOption
	// RadiusRing sets the outer radius of the ring, for example "40%".
	// Default is "40%".
	RadiusRing string
	// RadiusCenter is the radius for the center hole of the doughnut and must be smaller than RadiusRing.
	RadiusCenter string
	// CenterValues specifies what should be rendered in the center of the doughnut,
	// current options are "none" (default), "labels", "sum".
	// * labels - Will render the labels on the inside of the circle instead of the outside (more risk of collision).
	// * sum - Will put the sum count of all the series (formatted using ValueFormatter).
	CenterValues string
	// CenterValuesFontStyle provides the styling for center values (series labels prefer their specific series styling).
	CenterValuesFontStyle FontStyle
	// SegmentGap provides a margin between each series section.
	SegmentGap float64
	// ValueFormatter defines how float values are rendered to strings, notably for series labels.
	ValueFormatter ValueFormatter
}

DoughnutChartOption defines the options for rendering a doughnut chart. Render the chart using Painter.DoughnutChart.

func NewDoughnutChartOptionWithData added in v0.5.6

func NewDoughnutChartOptionWithData(data []float64) DoughnutChartOption

NewDoughnutChartOptionWithData returns an initialized DoughnutChartOption with the SeriesList set with the provided data slice.

type DoughnutSeries added in v0.5.6

type DoughnutSeries struct {
	// Value provides the value for the Doughnut section.
	Value float64
	// Label provides the series labels.
	Label SeriesLabel
	// Name specifies a name for the series.
	Name string
	// Radius for Doughnut chart, e.g.: 40%, default is "40%"
	Radius string
}

DoughnutSeries references a population of data for doughnut charts.

type DoughnutSeriesList added in v0.5.6

type DoughnutSeriesList []DoughnutSeries

DoughnutSeriesList provides the data populations for Doughnut charts (DoughnutChartOption).

func NewSeriesListDoughnut added in v0.5.6

func NewSeriesListDoughnut(values []float64, opts ...DoughnutSeriesOption) DoughnutSeriesList

NewSeriesListDoughnut builds a SeriesList for a doughnut chart.

func (DoughnutSeriesList) MaxValue added in v0.5.6

func (d DoughnutSeriesList) MaxValue() float64

MaxValue returns the maximum value within the series, or MinInt64 if no values.

func (DoughnutSeriesList) SetSeriesLabels added in v0.5.6

func (d DoughnutSeriesList) SetSeriesLabels(label SeriesLabel)

SetSeriesLabels sets the label for all elements in the series.

func (DoughnutSeriesList) SumSeries added in v0.5.6

func (d DoughnutSeriesList) SumSeries() float64

func (DoughnutSeriesList) ToGenericSeriesList added in v0.5.6

func (d DoughnutSeriesList) ToGenericSeriesList() GenericSeriesList

type DoughnutSeriesOption added in v0.5.6

type DoughnutSeriesOption struct {
	Label SeriesLabel
	Names []string
}

DoughnutSeriesOption provides series customization for NewSeriesListDoughnut.

type EChartStyle

type EChartStyle struct {
	Color   string   `json:"color"`
	Opacity *float64 `json:"opacity,omitempty"`
}

EChartStyle describes color and opacity for ECharts elements.

type EChartsAxisLabel

type EChartsAxisLabel struct {
	Formatter string `json:"formatter,omitempty"`
	Show      *bool  `json:"show,omitempty"`
	Color     string `json:"color,omitempty"`
	FontSize  *int   `json:"fontSize,omitempty"`
}

EChartsAxisLabel configures axis label display for ECharts.

type EChartsAxisLine added in v0.5.0

type EChartsAxisLine struct {
	Show      *bool `json:"show,omitempty"`
	LineStyle struct {
		Color   string   `json:"color,omitempty"`
		Opacity *float64 `json:"opacity,omitempty"`
		Width   *int     `json:"width,omitempty"` // TODO - add support
	} `json:"lineStyle,omitempty"`
}

EChartsAxisLine describes the line styling for an axis.

type EChartsBox added in v0.5.22

type EChartsBox struct {
	Top    int  `json:"top"`
	Bottom int  `json:"bottom"`
	Left   int  `json:"left"`
	Right  int  `json:"right"`
	IsSet  bool `json:"isSet"`
}

EChartsBox represents box dimensions with JSON tags for ECharts parsing.

func (EChartsBox) ToBox added in v0.5.22

func (eb EChartsBox) ToBox() Box

ToBox converts EChartsBox to Box.

type EChartsLabelOption

type EChartsLabelOption struct {
	Show     bool   `json:"show"`
	Distance int    `json:"distance"`
	Color    string `json:"color"`
}

EChartsLabelOption configures data labels.

type EChartsLegend

type EChartsLegend struct {
	Show            *bool            `json:"show"`
	Data            []string         `json:"data"`
	Align           string           `json:"align"`
	Orient          string           `json:"orient"`
	Padding         EChartsPadding   `json:"padding,omitempty"`
	Left            EChartsPosition  `json:"left"`
	Top             EChartsPosition  `json:"top"`
	TextStyle       EChartsTextStyle `json:"textStyle"`
	BackgroundColor string           `json:"backgroundColor,omitempty"` // TODO - add support
	BorderColor     string           `json:"borderColor,omitempty"`
}

EChartsLegend holds legend configuration from ECharts JSON.

type EChartsMarkData

type EChartsMarkData struct {
	Type string `json:"type"`
	// TODO - support position values below
	XAxis float64 `json:"xAxis,omitempty"`
	YAxis float64 `json:"yAxis,omitempty"`
}

EChartsMarkData represents mark lines or points in ECharts JSON.

func (*EChartsMarkData) UnmarshalJSON

func (emd *EChartsMarkData) UnmarshalJSON(data []byte) error

UnmarshalJSON parses mark definitions provided as an object or array.

type EChartsMarkLine

type EChartsMarkLine struct {
	Data []EChartsMarkData `json:"data"`
}

EChartsMarkLine defines mark lines for a series.

func (*EChartsMarkLine) ToSeriesMarkLine

func (eml *EChartsMarkLine) ToSeriesMarkLine() SeriesMarkLine

ToSeriesMarkLine converts the mark line to the internal representation.

type EChartsMarkPoint

type EChartsMarkPoint struct {
	SymbolSize int               `json:"symbolSize"`
	Data       []EChartsMarkData `json:"data"`
}

EChartsMarkPoint defines mark points for a series.

func (*EChartsMarkPoint) ToSeriesMarkPoint

func (emp *EChartsMarkPoint) ToSeriesMarkPoint() SeriesMarkPoint

ToSeriesMarkPoint converts the mark point to the internal representation.

type EChartsOption

type EChartsOption struct {
	Type       string         `json:"type"`
	Theme      string         `json:"theme"`
	FontFamily string         `json:"fontFamily"`
	Padding    EChartsPadding `json:"padding"`
	Box        EChartsBox     `json:"box"`
	Width      int            `json:"width"`
	Height     int            `json:"height"`
	Title      struct {
		Show            *bool            `json:"show,omitempty"`
		Text            string           `json:"text"`
		Subtext         string           `json:"subtext"`
		Left            EChartsPosition  `json:"left"`
		Top             EChartsPosition  `json:"top"`
		TextStyle       EChartsTextStyle `json:"textStyle"`
		SubtextStyle    EChartsTextStyle `json:"subtextStyle"`
		BackgroundColor string           `json:"backgroundColor,omitempty"` // TODO - add support
		BorderColor     string           `json:"borderColor,omitempty"`
	} `json:"title"`
	XAxis  EChartsXAxis  `json:"xAxis"`
	YAxis  EChartsYAxis  `json:"yAxis"`
	Legend EChartsLegend `json:"legend"`
	Radar  struct {
		Indicator []EChartsRadarIndicator `json:"indicator"`
	} `json:"radar"`
	Series          EChartsSeriesList `json:"series"`
	BackgroundColor string            `json:"backgroundColor,omitempty"`
	Children        []EChartsOption   `json:"children"`
}

EChartsOption mirrors a basic ECharts configuration.

func (*EChartsOption) ToOption

func (eo *EChartsOption) ToOption() ChartOption

ToOption converts the ECharts options into a ChartOption.

type EChartsPadding

type EChartsPadding struct {
	Box Box
}

EChartsPadding represents padding values around a component.

func (*EChartsPadding) UnmarshalJSON

func (eb *EChartsPadding) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes a padding array into a Box.

type EChartsPosition

type EChartsPosition string

EChartsPosition represents a CSS-like position value that can be either a string (like "center", "left") or a numeric value.

func (*EChartsPosition) UnmarshalJSON

func (p *EChartsPosition) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes a position JSON value that may be a string or number.

type EChartsRadarIndicator added in v0.5.22

type EChartsRadarIndicator struct {
	Name string  `json:"name"`
	Max  float64 `json:"max"`
	Min  float64 `json:"min"`
}

EChartsRadarIndicator maps radar indicator options from ECharts.

func (EChartsRadarIndicator) ToRadarIndicator added in v0.5.22

func (eri EChartsRadarIndicator) ToRadarIndicator() RadarIndicator

ToRadarIndicator converts to a RadarIndicator.

type EChartsSeries

type EChartsSeries struct {
	Data       []EChartsSeriesData `json:"data"`
	Name       string              `json:"name"`
	Type       string              `json:"type"`
	Radius     string              `json:"radius"`
	YAxisIndex int                 `json:"yAxisIndex"`
	ItemStyle  EChartStyle         `json:"itemStyle,omitempty"` // TODO - add support
	// label configuration
	Label     EChartsLabelOption `json:"label"`
	MarkPoint EChartsMarkPoint   `json:"markPoint"`
	MarkLine  EChartsMarkLine    `json:"markLine"`
	Max       *float64           `json:"max"` // TODO - add support
	Min       *float64           `json:"min"` // TODO - add support
}

EChartsSeries holds data and styling for one chart series.

type EChartsSeriesData

type EChartsSeriesData struct {
	Value     EChartsSeriesDataValue `json:"value"`
	Name      string                 `json:"name"`
	ItemStyle EChartStyle            `json:"itemStyle,omitempty"` // TODO - add support
}

EChartsSeriesData describes a single data item from ECharts.

func (*EChartsSeriesData) UnmarshalJSON

func (es *EChartsSeriesData) UnmarshalJSON(data []byte) error

UnmarshalJSON parses a series data item that may be a number or object.

type EChartsSeriesDataValue

type EChartsSeriesDataValue struct {
	// contains filtered or unexported fields
}

EChartsSeriesDataValue holds numeric values from an ECharts data entry.

func (*EChartsSeriesDataValue) First

func (value *EChartsSeriesDataValue) First() float64

First returns the first value or 0 when empty.

func (*EChartsSeriesDataValue) UnmarshalJSON

func (value *EChartsSeriesDataValue) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes a series data value that may be a single number or array.

type EChartsSeriesList

type EChartsSeriesList []EChartsSeries

EChartsSeriesList is a list of EChartsSeries values.

func (EChartsSeriesList) ToSeriesList

func (esList EChartsSeriesList) ToSeriesList() GenericSeriesList

type EChartsTextStyle

type EChartsTextStyle struct {
	Color      string  `json:"color"`
	FontFamily string  `json:"fontFamily"`
	FontSize   float64 `json:"fontSize"`
}

EChartsTextStyle maps text style options from ECharts.

func (*EChartsTextStyle) ToFontStyle added in v0.5.0

func (et *EChartsTextStyle) ToFontStyle() FontStyle

ToFontStyle converts the text style to a FontStyle.

type EChartsXAxis

type EChartsXAxis struct {
	Data []EChartsXAxisData
}

EChartsXAxis holds a list of x-axis options.

func (*EChartsXAxis) UnmarshalJSON

func (ex *EChartsXAxis) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes x-axis options that may be a single object or an array.

type EChartsXAxisData

type EChartsXAxisData struct {
	BoundaryGap *bool            `json:"boundaryGap,omitempty"`
	SplitNumber int              `json:"splitNumber,omitempty"`
	AxisLabel   EChartsAxisLabel `json:"axisLabel,omitempty"`
	AxisLine    EChartsAxisLine  `json:"axisLine,omitempty"`
	Data        []string         `json:"data"`
	Type        string           `json:"type"`
}

EChartsXAxisData holds x-axis configuration extracted from ECharts JSON.

type EChartsYAxis

type EChartsYAxis struct {
	Data []EChartsYAxisData `json:"data"`
}

EChartsYAxis represents a list of y-axis definitions.

func (*EChartsYAxis) UnmarshalJSON

func (ey *EChartsYAxis) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes y-axis options that may be a single object or an array.

type EChartsYAxisData

type EChartsYAxisData struct {
	Min       *float64         `json:"min,omitempty"`
	Max       *float64         `json:"max,omitempty"`
	AxisLabel EChartsAxisLabel `json:"axisLabel,omitempty"`
	AxisLine  EChartsAxisLine  `json:"axisLine,omitempty"`
	Data      []string         `json:"data"`
}

EChartsYAxisData holds a single y-axis configuration block.

type FontStyle added in v0.2.0

type FontStyle = chartdraw.FontStyle

FontStyle configures font properties including size, color, and family.

func NewFontStyleWithSize added in v0.4.7

func NewFontStyleWithSize(size float64) FontStyle

NewFontStyleWithSize constructs a new FontStyle with the specified font size. If you want to avoid directly constructing the FontStyle struct, you can use this followed by additional `WithX` function calls on the returned FontStyle.

type FunnelChartOption

type FunnelChartOption struct {
	// Theme specifies the colors used for the chart.
	Theme ColorPalette
	// Padding specifies the padding around the chart.
	Padding Box
	// Deprecated: Font is deprecated, instead the font needs to be set on the SeriesLabel, or other specific elements.
	Font *truetype.Font
	// SeriesList provides the data population for the chart. Typically constructed using NewSeriesListFunnel.
	SeriesList FunnelSeriesList
	// Title contains options for rendering the chart title.
	Title TitleOption
	// Legend contains options for the data legend.
	Legend LegendOption
	// Deprecated: ValueFormatter is deprecated, instead set the ValueFormatter at `SeriesList[*].Label.ValueFormatter`.
	ValueFormatter ValueFormatter
}

FunnelChartOption defines the options for rendering a funnel chart. Render the chart using Painter.FunnelChart.

func NewFunnelChartOptionWithData added in v0.4.0

func NewFunnelChartOptionWithData(data []float64) FunnelChartOption

NewFunnelChartOptionWithData returns an initialized FunnelChartOption with the SeriesList set with the provided data slice.

type FunnelSeries added in v0.5.0

type FunnelSeries struct {
	// Value provides the value for the funnel section.
	Value float64
	// Label provides the series labels.
	Label SeriesLabel
	// Name specifies a name for the series.
	Name string
}

FunnelSeries references a population of data for funnel charts.

type FunnelSeriesList added in v0.5.0

type FunnelSeriesList []FunnelSeries

FunnelSeriesList provides the data populations for funnel charts (FunnelChartOption).

func NewSeriesListFunnel added in v0.4.0

func NewSeriesListFunnel(values []float64, opts ...FunnelSeriesOption) FunnelSeriesList

NewSeriesListFunnel builds a series list for funnel charts.

func (FunnelSeriesList) SetSeriesLabels added in v0.5.6

func (f FunnelSeriesList) SetSeriesLabels(label SeriesLabel)

SetSeriesLabels sets the label for all elements in the series.

func (FunnelSeriesList) ToGenericSeriesList added in v0.5.0

func (f FunnelSeriesList) ToGenericSeriesList() GenericSeriesList

type FunnelSeriesOption added in v0.4.0

type FunnelSeriesOption struct {
	Label SeriesLabel
	Names []string
}

FunnelSeriesOption provides series customization for NewSeriesListFunnel.

type GenericSeries added in v0.5.0

type GenericSeries struct {
	// Type is the series chart type. Default is "line".
	Type string
	// Values provides the series data values.
	// For ChartTypeCandlestick, the Values field must contain OHLC data encoded as groups of 4 consecutive
	// float64 values: [Open, High, Low, Close, ...]. For N candlesticks, Values must have exactly N*4 elements.
	Values []float64
	// YAxisIndex is the y-axis to apply the series to: must be 0 or 1.
	YAxisIndex int
	// Label provides the series labels.
	Label SeriesLabel
	// Name specifies a name for the series.
	Name string
	// Radius for circular charts. Default is "40%".
	Radius string
	// MarkPoint provides a mark point configuration for this series. If Label is enabled, MarkPoint
	// replaces the label where rendered.
	MarkPoint SeriesMarkPoint
	// MarkLine provides amark line configuration for this series. When using MarkLine, configure
	// padding on the chart's right side to ensure space for the values.
	MarkLine SeriesMarkLine
}

GenericSeries references a population of data for any chart type. Chart-specific fields are only active for chart types that support them.

type GenericSeriesList added in v0.5.0

type GenericSeriesList []GenericSeries

GenericSeriesList provides the data populations for any chart type configured through ChartOption.

func NewSeriesListGeneric added in v0.5.0

func NewSeriesListGeneric(values [][]float64, chartType string) GenericSeriesList

NewSeriesListGeneric returns a Generic series list for the given values and chart type (used in ChartOption).

func (GenericSeriesList) SetSeriesLabels added in v0.5.6

func (g GenericSeriesList) SetSeriesLabels(label SeriesLabel)

SetSeriesLabels sets the label for all elements in the series.

type HeatMapAxis added in v0.5.1

type HeatMapAxis struct {
	// Title specifies the title to display next to the axis.
	Title string
	// TitleFontStyle specifies the font style for the axis title.
	TitleFontStyle FontStyle
	// Labels specifies custom labels for the axis. If empty, numeric indices are used.
	// Must match the data size for the corresponding axis.
	Labels []string
	// LabelFontStyle specifies the font style for the axis labels.
	LabelFontStyle FontStyle
	// LabelRotation is the rotation angle in radians for labels. Use DegreesToRadians(float64) to convert from degrees.
	LabelRotation float64
	// LabelCount is the number of labels to show on the axis. Use a smaller count to reduce text collisions.
	LabelCount int
	// LabelCountAdjustment specifies relative influence on label count.
	// Negative values result in cleaner graphs; positive values may cause text collisions.
	LabelCountAdjustment int
}

HeatMapAxis contains configuration options for an axis on a heat map chart.

type HeatMapOption added in v0.5.1

type HeatMapOption struct {
	// Theme specifies the color palette used for rendering the heat map.
	Theme ColorPalette
	// BaseColorIndex specifies which color from the theme palette to use as the base for gradients.
	BaseColorIndex int
	// Padding specifies the padding around the heat map chart.
	Padding Box
	// Deprecated: Font is deprecated, instead the font needs to be set on the SeriesLabel, or other specific elements.
	Font *truetype.Font
	// Title contains options for rendering the chart title.
	Title TitleOption
	// Values provides the 2D data for the heat map.
	// The outer slice represents the rows (y-axis) and the inner slice represents the columns (x-axis).
	Values [][]float64
	// XAxis contains configuration options for the x-axis.
	XAxis HeatMapAxis
	// YAxis contains configuration options for the y-axis.
	YAxis HeatMapAxis
	// ScaleMinValue overrides the minimum value for color gradient calculation. If nil, calculated from the data.
	ScaleMinValue *float64
	// ScaleMaxValue overrides the maximum value for color gradient calculation. If nil, calculated from the data.
	ScaleMaxValue *float64
	// ValuesLabel contains configuration for displaying numeric values on heat map cells.
	ValuesLabel SeriesLabel
}

HeatMapOption contains configuration options for a heat map chart. Render the chart using Painter.HeatMapChart.

func NewHeatMapOptionWithData added in v0.5.1

func NewHeatMapOptionWithData(data [][]float64) HeatMapOption

NewHeatMapOptionWithData returns an initialized HeatMapOption with the provided data.

type HorizontalBarChartOption

type HorizontalBarChartOption struct {
	// Theme specifies the colors used for the chart.
	Theme ColorPalette
	// Padding specifies the padding around the chart.
	Padding Box
	// Deprecated: Font is deprecated, instead the font needs to be set on the SeriesLabel, or other specific elements.
	Font *truetype.Font
	// SeriesList provides the data population for the chart. Typically constructed using NewSeriesListHorizontalBar.
	SeriesList HorizontalBarSeriesList
	// StackSeries when *true renders the series stacked within one bar.
	// This causes some options, including BarMargin and SeriesLabelPosition, to be
	// ignored. MarkLine only renders for the first series.
	StackSeries *bool
	// SeriesLabelPosition specifies the label position for the series: "left" or "right".
	SeriesLabelPosition string
	// XAxis contains options for the x-axis.
	XAxis XAxisOption
	// YAxis contains options for the y-axis.
	YAxis YAxisOption
	// Title contains options for rendering the chart title.
	Title TitleOption
	// Legend contains options for the data legend.
	Legend LegendOption
	// BarHeight specifies the height of each horizontal bar. Height may be reduced to ensure all series fit on the chart.
	BarHeight int // TODO - v0.6 - Update to float64 to represent a precent
	// BarMargin specifies the margin between grouped bars. BarHeight takes priority over a set margin.
	BarMargin *float64 // TODO - v0.6 - Update to be percent based
	// ValueFormatter defines how float values are rendered to strings, notably for numeric axis labels.
	ValueFormatter ValueFormatter
}

HorizontalBarChartOption defines the options for rendering a horizontal bar chart. Render the chart using Painter.HorizontalBarChart.

func NewHorizontalBarChartOptionWithData added in v0.4.0

func NewHorizontalBarChartOptionWithData(data [][]float64) HorizontalBarChartOption

NewHorizontalBarChartOptionWithData returns an initialized HorizontalBarChartOption with the SeriesList set with the provided data slice.

type HorizontalBarSeries added in v0.5.0

type HorizontalBarSeries struct {
	// Values provides the series data values.
	Values []float64
	// Label provides the series labels.
	Label SeriesLabel
	// Name specifies a name for the series.
	Name string
	// MarkLine provides a configuration for mark lines for this series.
	MarkLine SeriesMarkLine
}

HorizontalBarSeries references a population of data for horizontal bar charts.

func (*HorizontalBarSeries) Summary added in v0.5.0

func (h *HorizontalBarSeries) Summary() populationSummary

type HorizontalBarSeriesList added in v0.5.0

type HorizontalBarSeriesList []HorizontalBarSeries

HorizontalBarSeriesList provides the data populations for horizontal bar charts (HorizontalBarChartOption).

func NewSeriesListHorizontalBar added in v0.4.0

func NewSeriesListHorizontalBar(values [][]float64, opts ...BarSeriesOption) HorizontalBarSeriesList

NewSeriesListHorizontalBar builds a SeriesList for a horizontal bar chart. Horizontal bar charts are unique in that these Series can not be combined with any other chart type.

func (HorizontalBarSeriesList) SetSeriesLabels added in v0.5.6

func (h HorizontalBarSeriesList) SetSeriesLabels(label SeriesLabel)

SetSeriesLabels sets the label for all elements in the series.

func (HorizontalBarSeriesList) SumSeries added in v0.5.0

func (h HorizontalBarSeriesList) SumSeries() []float64

SumSeries returns a float64 slice with the sum of each series.

func (HorizontalBarSeriesList) SumSeriesValues added in v0.5.0

func (h HorizontalBarSeriesList) SumSeriesValues() []float64

SumSeriesValues returns a float64 slice with each series totaled by the value index.

func (HorizontalBarSeriesList) ToGenericSeriesList added in v0.5.0

func (h HorizontalBarSeriesList) ToGenericSeriesList() GenericSeriesList

type LabelStyle added in v0.5.16

type LabelStyle struct {
	// FontStyle overrides font properties (color, size, family) for this specific label.
	FontStyle FontStyle
	// BackgroundColor provides a background color behind the label text.
	BackgroundColor Color
	// CornerRadius sets the radius for rounded corners on the background rectangle.
	CornerRadius int
	// BorderColor sets the border color around the label background.
	BorderColor Color
	// BorderWidth sets the width of the border around the label background.
	BorderWidth float64
}

LabelStyle contains optional styling overrides for individual label rendering. All fields are optional - zero values mean "use default styling from series or theme".

type LayoutBuilderGrid added in v0.5.19

type LayoutBuilderGrid interface {
	// CellAt defines a new cell at the specified position with the given name.
	// The cell defaults to a 1x1 span, adjust larger by calling Span.
	CellAt(name string, col, row int) LayoutBuilderGrid
	// Span modifies the span of the previously defined cell.
	// Must be called after CellAt.
	Span(colSpan, rowSpan int) LayoutBuilderGrid
	// Offset applies position adjustments to the previously defined cell.
	// Accepts pixels ("20") or percentages ("10%") - percentages are relative to the cell's own dimensions.
	// Must be called after CellAt. Useful for fine-tuning and creating overlapping effects.
	Offset(x, y string) LayoutBuilderGrid
	// Build creates child painters based on the defined grid layout.
	// Returns a map of cell names to their corresponding painters.
	Build() (map[string]*Painter, error)
}

LayoutBuilderGrid is returned by Painter.LayoutByGrid() and provides methods for building grid-based layouts with cell spanning support.

type LayoutBuilderRow added in v0.5.19

type LayoutBuilderRow interface {
	// Row starts defining a new row.
	// If the current row has columns, it commits the row and starts a new one.
	// If the current row is empty, this is a no-op (prevents accidental empty rows).
	// Multiple consecutive Row() calls without column definitions are idempotent.
	Row() LayoutBuilderRow
	// RowGap adds vertical spacing between rows (pixels or percentage).
	// Creates an empty row with the specified height (equivalent to Row().Height(height)).
	RowGap(height string) LayoutBuilderRow
	// Columns adds columns with equal width distribution to the current row. Use Col if you want to set a specific column width.
	Columns(names ...string) LayoutBuilderRow
	// Col adds a column with specified width to the current row (pixels, percentage, or empty for auto).
	Col(name string, width string) LayoutBuilderRow
	// Height sets the current row height (pixels or percentage).
	Height(height string) LayoutBuilderRow
	// ColGap adds a horizontal gap in the current row (like adding an invisible column).
	// If gap is empty (""), it is treated as an auto-width gap and will
	// match other auto-width columns in the row.
	ColGap(gap string) LayoutBuilderRow
	// RowOffset applies position adjustments to the entire current row. Unlike Offset (which is cell specific),
	// this adjustment will adjust all rows following.
	// Accepts pixels ("20") or percentages ("10%") - percentages are relative to the painter height.
	// Negative values create overlapping effects, positive values create gaps.
	RowOffset(y string) LayoutBuilderRow
	// Offset applies position adjustments to the last added column in the current row.
	// Accepts pixels ("20") or percentages ("10%") - percentages are relative to the cell's dimensions.
	// X offset percentage is relative to the cell's width, Y offset percentage is relative to the row's height.
	// Negative values create overlapping effects. If no columns have been added yet, this is a no-op.
	Offset(x, y string) LayoutBuilderRow
	// Build creates child painters from the entire layout definition.
	// Returns a map of cell names to their corresponding painters.
	Build() (map[string]*Painter, error)
}

LayoutBuilderRow is returned by Painter.LayoutByRows() and provides methods for building row-based layouts. The builder starts already in a row context, ready to define columns immediately.

type LegendOption

type LegendOption struct {
	// Show specifies if the legend should be rendered. Set to *false (via Ptr(false)) to hide the legend.
	Show *bool
	// Theme specifies the colors used for the legend.
	Theme ColorPalette
	// SeriesNames provides the text labels for the data series.
	SeriesNames []string
	// FontStyle specifies the font, size, and style for legend text.
	FontStyle FontStyle
	// Padding specifies the space around the legend.
	Padding Box
	// Offset specifies the position of the legend relative to the left and top sides.
	Offset OffsetStr
	// Align is the legend marker and text alignment: 'left', 'right', or 'center'. Default is 'left'.
	Align string
	// Vertical when set to *true makes the legend orientation vertical.
	Vertical *bool
	// Symbol defines the icon shape next to each label. Options: 'square', 'dot', 'diamond', 'circle'.
	Symbol Symbol // TODO - should Symbol configuration be changed now that we support per-series symbols
	// TODO - v0.6 - consider combining symbol with size into a SymbolStyle struct
	// OverlayChart when set to *true renders the legend over the chart. Ignored if Vertical is true (Vertical always forces overlay).
	OverlayChart *bool
	// BorderWidth can be set to a non-zero value to render a box around the legend.
	BorderWidth float64
	// contains filtered or unexported fields
}

LegendOption defines the configuration for rendering the chart legend.

func (*LegendOption) IsEmpty

func (opt *LegendOption) IsEmpty() bool

IsEmpty checks if the legend is empty.

type LineChartOption

type LineChartOption struct {
	// Theme specifies the colors used for the line chart.
	Theme ColorPalette
	// Padding specifies the padding around the chart.
	Padding Box
	// Deprecated: Font is deprecated, instead the font needs to be set on the SeriesLabel, or other specific elements.
	Font *truetype.Font
	// SeriesList provides the data population for the chart. Typically constructed using NewSeriesListLine.
	SeriesList LineSeriesList
	// StackSeries when true layers each series so the last represents the cumulative sum.
	// This forces FillArea and ignores options like StrokeSmoothingTension.
	// MarkLine only renders for the first series, and only the first y-axis is stacked.
	StackSeries *bool
	// XAxis contains options for the x-axis.
	XAxis XAxisOption
	// YAxis contains options for the y-axis. At most two y-axes are supported.
	YAxis []YAxisOption
	// Title contains options for rendering the chart title.
	Title TitleOption
	// Legend contains options for the data legend.
	Legend LegendOption
	// Symbol specifies the symbol to draw at data points. Empty (default) varies by dataset.
	// Options: 'none', 'circle', 'dot', 'square', 'diamond'. Can be overridden per series.
	Symbol Symbol // TODO - v0.6 - consider combining symbol with size into a SymbolStyle struct
	// LineStrokeWidth is the width of the rendered line.
	LineStrokeWidth float64
	// StrokeSmoothingTension controls line smoothing (0-1). 0 creates straight lines, 1 creates heavily smoothed curves.
	// Smoothing the line may move it from hitting points exactly.
	// Higher tension values move the line further from exact data points.
	StrokeSmoothingTension float64
	// FillArea when set to *true fills the area below the line.
	FillArea *bool
	// FillOpacity is the opacity/alpha (0-255) of the area fill.
	FillOpacity uint8
	// ValueFormatter defines how float values are rendered to strings, notably for numeric axis labels.
	ValueFormatter ValueFormatter
}

LineChartOption defines the options for rendering a line chart. Render the chart using Painter.LineChart.

func NewLineChartOptionWithData added in v0.4.0

func NewLineChartOptionWithData(data [][]float64) LineChartOption

NewLineChartOptionWithData returns an initialized LineChartOption with the SeriesList set with the provided data slice.

func NewLineChartOptionWithSeries added in v0.5.9

func NewLineChartOptionWithSeries(sl LineSeriesList) LineChartOption

NewLineChartOptionWithSeries returns an initialized LineChartOption with the provided SeriesList.

type LineSeries added in v0.5.0

type LineSeries struct {
	// Values provides the series data values.
	Values []float64
	// YAxisIndex is the index for the axis, it must be 0 or 1.
	YAxisIndex int
	// Label provides the series labels.
	Label SeriesLabel
	// Name specifies a name for the series.
	Name string
	// MarkPoint provides a configuration for mark points for this series. If Label is also enabled, the MarkPoint
	// will replace the label where rendered.
	MarkPoint SeriesMarkPoint
	// MarkLine provides a configuration for mark lines for this series. When using a MarkLine, you will want to
	// configure padding to the chart on the right for the values.
	MarkLine SeriesMarkLine
	// TrendLine provides configurations for trend lines for this series.
	TrendLine []SeriesTrendLine
	// Symbol specifies a custom symbol for the series.
	Symbol Symbol // TODO - v0.6 - consider combining symbol with size into a SymbolStyle struct
	// contains filtered or unexported fields
}

LineSeries references a population of data for line charts.

func (*LineSeries) Summary added in v0.5.0

func (l *LineSeries) Summary() populationSummary

type LineSeriesList added in v0.5.0

type LineSeriesList []LineSeries

LineSeriesList provides the data populations for line charts (LineChartOption).

func NewSeriesListLine added in v0.4.0

func NewSeriesListLine(values [][]float64, opts ...LineSeriesOption) LineSeriesList

NewSeriesListLine builds a SeriesList for a line chart. The first dimension of the values indicates the population of the data, while the second dimension provides the samples for the population.

func (LineSeriesList) SetSeriesLabels added in v0.5.6

func (l LineSeriesList) SetSeriesLabels(label SeriesLabel)

SetSeriesLabels sets the label for all elements in the series.

func (LineSeriesList) SumSeries added in v0.5.0

func (l LineSeriesList) SumSeries() []float64

SumSeries returns a float64 slice with the sum of each series.

func (LineSeriesList) SumSeriesValues added in v0.5.0

func (l LineSeriesList) SumSeriesValues() []float64

SumSeriesValues returns a float64 slice with each series totaled by the value index.

func (LineSeriesList) ToGenericSeriesList added in v0.5.0

func (l LineSeriesList) ToGenericSeriesList() GenericSeriesList

type LineSeriesOption added in v0.4.0

type LineSeriesOption struct {
	Label     SeriesLabel
	Names     []string
	MarkPoint SeriesMarkPoint
	MarkLine  SeriesMarkLine
	TrendLine []SeriesTrendLine
}

LineSeriesOption provides series customization for NewSeriesListLine.

type OHLCData added in v0.5.17

type OHLCData struct {
	// Open is the opening price for the time period.
	Open float64
	// High is the highest price during the time period.
	High float64
	// Low is the lowest price during the time period.
	Low float64
	// Close is the closing price for the time period.
	Close float64
}

OHLCData represents Open, High, Low, Close financial data for a single time period. All values must satisfy: High >= Open, Close and Low <= Open, Close for valid candlesticks.

type OffsetInt added in v0.3.0

type OffsetInt struct {
	// Top indicates a vertical spacing adjustment from the top.
	Top int
	// Left indicates a horizontal spacing adjustment from the left.
	Left int
}

OffsetInt provides an ability to configure a shift from the top or left alignments.

func (OffsetInt) WithLeft added in v0.3.0

func (o OffsetInt) WithLeft(val int) OffsetInt

WithLeft returns a copy of the offset with the Left value set.

func (OffsetInt) WithTop added in v0.3.0

func (o OffsetInt) WithTop(val int) OffsetInt

WithTop returns a copy of the offset with the Top value set.

type OffsetStr added in v0.3.0

type OffsetStr struct {
	// Left is the distance between the component and the left side of the container.
	// It can be pixel value (20), percentage value (20%), or position description: 'left', 'right', 'center'.
	Left string
	// Top is the distance between the component and the top side of the container.
	// It can be pixel value (20), or percentage value (20%), or position description: 'top', 'bottom'.
	Top string
}

OffsetStr provides an ability to configure a shift from the top or left alignments using flexible string inputs.

func (OffsetStr) WithLeft added in v0.3.0

func (o OffsetStr) WithLeft(val string) OffsetStr

WithLeft returns a copy of the offset with the Left value set.

func (OffsetStr) WithLeftI added in v0.3.0

func (o OffsetStr) WithLeftI(val int) OffsetStr

WithLeftI sets Left using an integer value.

func (OffsetStr) WithTop added in v0.3.0

func (o OffsetStr) WithTop(val string) OffsetStr

WithTop returns a copy of the offset with the Top value set.

func (OffsetStr) WithTopI added in v0.3.0

func (o OffsetStr) WithTopI(val int) OffsetStr

WithTopI sets Top using an integer value.

type OptionFunc

type OptionFunc func(opt *ChartOption)

OptionFunc is a function that modifies ChartOption.

func ChildOptionFunc

func ChildOptionFunc(child ...ChartOption) OptionFunc

ChildOptionFunc adds a Child chart on top of the current one. Use Padding and Box for positioning.

func DimensionsOptionFunc added in v0.4.0

func DimensionsOptionFunc(width, height int) OptionFunc

DimensionsOptionFunc sets the width and height dimensions of the chart.

func FontOptionFunc deprecated

func FontOptionFunc(font *truetype.Font) OptionFunc

Deprecated: FontOptionFunc is deprecated, fonts should be set on the specific elements (SeriesLabel, Title, etc).

func JPGOutputOptionFunc added in v0.5.1

func JPGOutputOptionFunc() OptionFunc

JPGOutputOptionFunc sets JPG as the image output format for the chart.

func LegendLabelsOptionFunc

func LegendLabelsOptionFunc(labels []string) OptionFunc

LegendLabelsOptionFunc sets the legend series name labels of the chart.

func LegendOptionFunc

func LegendOptionFunc(legend LegendOption) OptionFunc

LegendOptionFunc sets the legend of the chart.

func MarkLineOptionFunc

func MarkLineOptionFunc(seriesIndex int, markLineTypes ...string) OptionFunc

MarkLineOptionFunc sets the mark line for series of the chart.

func MarkPointOptionFunc

func MarkPointOptionFunc(seriesIndex int, markPointTypes ...string) OptionFunc

MarkPointOptionFunc sets the mark point for series of the chart.

func PNGOutputOptionFunc added in v0.4.0

func PNGOutputOptionFunc() OptionFunc

PNGOutputOptionFunc sets PNG as the image output format for the chart.

func PaddingOptionFunc

func PaddingOptionFunc(padding Box) OptionFunc

PaddingOptionFunc sets the padding of the chart.

func RadarIndicatorOptionFunc

func RadarIndicatorOptionFunc(names []string, values []float64) OptionFunc

RadarIndicatorOptionFunc sets the radar indicator of chart

func SVGOutputOptionFunc added in v0.4.0

func SVGOutputOptionFunc() OptionFunc

SVGOutputOptionFunc sets SVG as the image output format for the chart.

func SeriesShowLabel added in v0.4.0

func SeriesShowLabel(show bool) OptionFunc

SeriesShowLabel sets the series show label state for all series.

func ThemeNameOptionFunc

func ThemeNameOptionFunc(theme string) OptionFunc

ThemeNameOptionFunc sets the chart theme by name.

func ThemeOptionFunc

func ThemeOptionFunc(theme ColorPalette) OptionFunc

ThemeOptionFunc sets the theme of the chart.

func TitleOptionFunc

func TitleOptionFunc(title TitleOption) OptionFunc

TitleOptionFunc sets the title of the chart.

func TitleTextOptionFunc

func TitleTextOptionFunc(text string, subtext ...string) OptionFunc

TitleTextOptionFunc sets the title text of chart.

func XAxisLabelsOptionFunc added in v0.4.9

func XAxisLabelsOptionFunc(labels []string) OptionFunc

XAxisLabelsOptionFunc sets the x-axis labels of the chart.

func XAxisOptionFunc

func XAxisOptionFunc(xAxisOption XAxisOption) OptionFunc

XAxisOptionFunc sets the x-axis of the chart.

func YAxisLabelsOptionFunc added in v0.4.9

func YAxisLabelsOptionFunc(labels []string) OptionFunc

YAxisLabelsOptionFunc sets the y-axis labels of the chart.

func YAxisOptionFunc

func YAxisOptionFunc(yAxisOption ...YAxisOption) OptionFunc

YAxisOptionFunc sets the y-axis of chart, supports up to two y-axis.

type Painter

type Painter struct {
	// contains filtered or unexported fields
}

Painter is the primary struct for drawing charts/graphs.

func BarRender

func BarRender(values [][]float64, opts ...OptionFunc) (*Painter, error)

BarRender renders a bar chart.

func CandleStickRender added in v0.5.17

func CandleStickRender(values [][]OHLCData, opts ...OptionFunc) (*Painter, error)

CandleStickRender renders a candlestick chart.

func DoughnutRender added in v0.5.6

func DoughnutRender(values []float64, opts ...OptionFunc) (*Painter, error)

DoughnutRender renders a doughnut or ring chart.

func FunnelRender

func FunnelRender(values []float64, opts ...OptionFunc) (*Painter, error)

FunnelRender renders a funnel chart.

func HorizontalBarRender

func HorizontalBarRender(values [][]float64, opts ...OptionFunc) (*Painter, error)

HorizontalBarRender renders a horizontal bar chart.

func LineRender

func LineRender(values [][]float64, opts ...OptionFunc) (*Painter, error)

LineRender renders a line chart.

func NewPainter

func NewPainter(opts PainterOptions, opt ...PainterOptionFunc) *Painter

NewPainter creates a painter for rendering charts.

func PieRender

func PieRender(values []float64, opts ...OptionFunc) (*Painter, error)

PieRender renders a pie chart.

func RadarRender

func RadarRender(values [][]float64, opts ...OptionFunc) (*Painter, error)

RadarRender renders a radar chart.

func Render

func Render(opt ChartOption, opts ...OptionFunc) (*Painter, error)

Render creates and renders a chart based on the provided options.

func ScatterRender added in v0.5.0

func ScatterRender(values [][]float64, opts ...OptionFunc) (*Painter, error)

ScatterRender renders a scatter chart.

func TableOptionRenderDirect added in v0.4.0

func TableOptionRenderDirect(opt TableChartOption) (*Painter, error)

TableOptionRenderDirect renders a table directly to an image with the provided options. Table options differ from other charts as they include Painter initialization state. To render a table on an existing Painter, use TableOptionRender.

func TableRenderValues added in v0.4.0

func TableRenderValues(header []string, data [][]string, spanMaps ...map[int]int) (*Painter, error)

TableRenderValues renders a table chart with the provided header and data values.

func (*Painter) ArrowDown added in v0.4.0

func (p *Painter) ArrowDown(x, y, width, height int,
	fillColor, strokeColor Color, strokeWidth float64)

ArrowDown draws an arrow at the given point and dimensions pointing down.

func (*Painter) ArrowLeft

func (p *Painter) ArrowLeft(x, y, width, height int,
	fillColor, strokeColor Color, strokeWidth float64)

ArrowLeft draws an arrow at the given point and dimensions pointing left.

func (*Painter) ArrowRight

func (p *Painter) ArrowRight(x, y, width, height int,
	fillColor, strokeColor Color, strokeWidth float64)

ArrowRight draws an arrow at the given point and dimensions pointing right.

func (*Painter) ArrowUp added in v0.4.0

func (p *Painter) ArrowUp(x, y, width, height int,
	fillColor, strokeColor Color, strokeWidth float64)

ArrowUp draws an arrow at the given point and dimensions pointing up.

func (*Painter) BarChart added in v0.4.0

func (p *Painter) BarChart(opt BarChartOption) error

BarChart renders a bar chart with the provided configuration to the painter.

func (*Painter) Bytes

func (p *Painter) Bytes() ([]byte, error)

Bytes returns the final rendered data as a byte slice.

func (*Painter) CandlestickChart added in v0.5.17

func (p *Painter) CandlestickChart(opt CandlestickChartOption) error

CandlestickChart renders a candlestick chart with the provided configuration to the painter.

func (*Painter) Child

func (p *Painter) Child(opt ...PainterOptionFunc) *Painter

Child returns a painter with the provided options applied. Useful for rendering relative to a portion of the canvas via PainterBoxOption.

func (*Painter) Circle

func (p *Painter) Circle(radius float64, x, y int, fillColor, strokeColor Color, strokeWidth float64)

Circle draws a circle at the given coords with a given radius.

func (*Painter) DashedLineStroke added in v0.5.17

func (p *Painter) DashedLineStroke(points []Point, strokeColor Color, strokeWidth float64, strokeDashArray []float64)

DashedLineStroke draws line segments through the provided points with dashed strokes. Points with values of math.MaxInt32 are skipped, resulting in a gap.

func (*Painter) Dots

func (p *Painter) Dots(points []Point, fillColor, strokeColor Color, strokeWidth float64, dotRadius float64)

Dots prints filled circles for the given points.

func (*Painter) DoughnutChart added in v0.5.6

func (p *Painter) DoughnutChart(opt DoughnutChartOption) error

DoughnutChart renders a doughnut or ring chart with the provided configuration to the painter.

func (*Painter) FillArea

func (p *Painter) FillArea(points []Point, fillColor Color)

FillArea draws a filled polygon through the given points, skipping "null" (MaxInt32) break values (filling the area flat between them).

func (*Painter) FilledDiamond added in v0.4.9

func (p *Painter) FilledDiamond(cx, cy, width, height int, fillColor, strokeColor Color, strokeWidth float64)

FilledDiamond draws a filled diamond centered at (cx, cy) with the given width and height.

func (*Painter) FilledRect added in v0.4.3

func (p *Painter) FilledRect(x1, y1, x2, y2 int, fillColor, strokeColor Color, strokeWidth float64)

FilledRect draws a filled box with the given coordinates.

func (*Painter) FunnelChart added in v0.4.0

func (p *Painter) FunnelChart(opt FunnelChartOption) error

FunnelChart renders a funnel chart with the provided configuration to the painter.

func (*Painter) HeatMapChart added in v0.5.1

func (p *Painter) HeatMapChart(opt HeatMapOption) error

HeatMapChart renders a heat map with the provided configuration to the painter.

func (*Painter) Height

func (p *Painter) Height() int

Height returns the drawable height of the painter's box.

func (*Painter) HorizontalBarChart added in v0.4.0

func (p *Painter) HorizontalBarChart(opt HorizontalBarChartOption) error

HorizontalBarChart renders a horizontal bar chart with the provided configuration to the painter.

func (*Painter) HorizontalMarkLine added in v0.4.10

func (p *Painter) HorizontalMarkLine(x, y, width int, fillColor, strokeColor Color, strokeWidth float64, strokeDashArray []float64)

HorizontalMarkLine draws a horizontal line with a small circle and arrow at the right.

func (*Painter) LayoutByGrid added in v0.5.19

func (p *Painter) LayoutByGrid(cols, rows int) LayoutBuilderGrid

LayoutByGrid returns builder for dividing the painter into child painters with a grid based layout. This is typically the easiest way to align multiple charts on to a single Painter. Specify how many rows and columns the painter should be divided into, then define each child painter using CellAt and Span.

func (*Painter) LayoutByRows added in v0.5.19

func (p *Painter) LayoutByRows() LayoutBuilderRow

LayoutByRows returns builder for dividing the painter into child painters with a row-based layout. This provides a flexible way to create dashboards and complex layouts where rows are built progressively. The builder starts already in a row context, ready to accept column definitions immediately.

func (*Painter) LineChart added in v0.4.0

func (p *Painter) LineChart(opt LineChartOption) error

LineChart renders a line chart with the provided configuration to the painter.

func (*Painter) LineStroke

func (p *Painter) LineStroke(points []Point, strokeColor Color, strokeWidth float64)

LineStroke draws a line in the graph from point to point with the specified stroke color/width. Points with values of math.MaxInt32 are skipped, resulting in a gap. Single or isolated points result in just a dot being drawn at the point.

func (*Painter) MeasureText

func (p *Painter) MeasureText(text string, textRotation float64, fontStyle FontStyle) Box

MeasureText returns the rendered size of the text for the provided font style.

func (*Painter) PieChart added in v0.4.0

func (p *Painter) PieChart(opt PieChartOption) error

PieChart renders a pie chart with the provided configuration to the painter.

func (*Painter) Pin

func (p *Painter) Pin(x, y, width int, fillColor, strokeColor Color, strokeWidth float64)

Pin draws a pin shape (circle + curved tail).

func (*Painter) Polygon

func (p *Painter) Polygon(center Point, radius float64, sides int, strokeColor Color, strokeWidth float64)

Polygon draws a polygon with the specified center, radius, and number of sides.

func (*Painter) RadarChart added in v0.4.0

func (p *Painter) RadarChart(opt RadarChartOption) error

RadarChart renders a radar chart with the provided configuration to the painter.

func (*Painter) ScatterChart added in v0.5.0

func (p *Painter) ScatterChart(opt ScatterChartOption) error

ScatterChart renders a scatter chart with the provided configuration to the painter.

func (*Painter) SmoothDashedLineStroke added in v0.5.17

func (p *Painter) SmoothDashedLineStroke(points []Point, tension float64, strokeColor Color, strokeWidth float64, strokeDashArray []float64)

SmoothDashedLineStroke draws a smooth dashed curve through the given points.

func (*Painter) SmoothLineStroke

func (p *Painter) SmoothLineStroke(points []Point, tension float64, strokeColor Color, strokeWidth float64)

SmoothLineStroke draws a smooth curve through the given points using Quadratic Bézier segments and a tension parameter in [0..1] with 0 providing straight lines between midpoints and 1 providing a smoother line. Because tension smooths out the line, the line no longer hits the provided points exactly. The more variable the points and the higher the tension, the more the line deviates.

func (*Painter) TableChart added in v0.4.0

func (p *Painter) TableChart(opt TableChartOption) error

TableChart renders a table with the provided configuration to the painter.

func (*Painter) Text

func (p *Painter) Text(body string, x, y int, radians float64, fontStyle FontStyle)

Text draws the given string at the specified position using the given font style. Specifying radians rotates the text.

func (*Painter) TextFit

func (p *Painter) TextFit(body string, x, y, width int, fontStyle FontStyle, textAligns ...string) Box

TextFit draws multi-line text constrained to a given width.

func (*Painter) VerticalMarkLine added in v0.4.10

func (p *Painter) VerticalMarkLine(x, y, height int, fillColor, strokeColor Color, strokeWidth float64, strokeDashArray []float64)

VerticalMarkLine draws a vertical line with a small dot at the bottom and an arrow at the top.

func (*Painter) Width

func (p *Painter) Width() int

Width returns the drawable width of the painter's box.

type PainterOptionFunc added in v0.4.0

type PainterOptionFunc func(*Painter)

PainterOptionFunc defines a function that can modify a Painter after creation.

func PainterBoxOption

func PainterBoxOption(box Box) PainterOptionFunc

PainterBoxOption sets a specific drawing area for the Painter.

func PainterFontOption

func PainterFontOption(font *truetype.Font) PainterOptionFunc

PainterFontOption sets the default font face for the Painter. Used when FontStyle in chart configs doesn't specify a font.

func PainterPaddingOption

func PainterPaddingOption(padding Box) PainterOptionFunc

PainterPaddingOption sets the padding within the painter canvas.

func PainterThemeOption

func PainterThemeOption(theme ColorPalette) PainterOptionFunc

PainterThemeOption sets the default theme for the Painter. Used when specific chart options don't have a theme set.

type PainterOptions

type PainterOptions struct {
	// OutputFormat specifies the output type: "svg", "png", "jpg". Default is "png".
	OutputFormat string
	// Width is the width of the painter canvas.
	Width int
	// Height is the height of the painter canvas.
	Height int
	// Font is the default font for rendering text.
	Font *truetype.Font
	// Theme is the default theme used when charts don't specify one.
	Theme ColorPalette
}

PainterOptions contains parameters for creating a new Painter.

type PatternDetectionResult added in v0.5.17

type PatternDetectionResult struct {
	// Index is the pattern's series data point position.
	Index int
	// PatternName is the display name (e.g., "Doji", "Hammer").
	PatternName string
	// PatternType is the identifier constant (e.g., CandlestickPatternDoji).
	PatternType string
}

PatternDetectionResult holds detected pattern information.

type PatternFormatter added in v0.5.17

type PatternFormatter func(patterns []PatternDetectionResult, seriesName string, value float64) (string, *LabelStyle)

PatternFormatter allows custom formatting of detected patterns.

type PieChartOption

type PieChartOption struct {
	// Theme specifies the colors used for the pie chart.
	Theme ColorPalette
	// Padding specifies the padding around the chart.
	Padding Box
	// Deprecated: Font is deprecated, instead the font needs to be set on the SeriesLabel, or other specific elements.
	Font *truetype.Font
	// SeriesList provides the data population for the chart. Typically constructed using NewSeriesListPie.
	SeriesList PieSeriesList
	// Title contains options for rendering the chart title.
	Title TitleOption
	// Legend contains options for the data legend.
	Legend LegendOption
	// Radius sets the pie radius. Default is "40%".
	Radius string
	// SegmentGap provides the gap between each pie slice.
	SegmentGap float64
	// Deprecated: ValueFormatter is deprecated, instead set the ValueFormatter at `SeriesList[*].Label.ValueFormatter`.
	ValueFormatter ValueFormatter
}

PieChartOption defines the options for rendering a pie chart. Render the chart using Painter.PieChart.

func NewPieChartOptionWithData added in v0.4.0

func NewPieChartOptionWithData(data []float64) PieChartOption

NewPieChartOptionWithData returns an initialized PieChartOption with the SeriesList set with the provided data slice.

type PieSeries added in v0.5.0

type PieSeries struct {
	// Value provides the value for the pie section.
	Value float64
	// Label provides the series labels.
	Label SeriesLabel
	// Name specifies a name for the series.
	Name string
	// Radius for Pie chart, e.g.: 40%, default is "40%"
	Radius string
}

PieSeries references a population of data for pie charts.

type PieSeriesList added in v0.5.0

type PieSeriesList []PieSeries

PieSeriesList provides the data populations for pie charts (PieChartOption).

func NewSeriesListPie added in v0.4.0

func NewSeriesListPie(values []float64, opts ...PieSeriesOption) PieSeriesList

NewSeriesListPie builds a SeriesList for a pie chart.

func (PieSeriesList) MaxValue added in v0.5.0

func (p PieSeriesList) MaxValue() float64

MaxValue returns the maximum value within the series, or MinInt64 if no values.

func (PieSeriesList) SetSeriesLabels added in v0.5.6

func (p PieSeriesList) SetSeriesLabels(label SeriesLabel)

SetSeriesLabels sets the label for all elements in the series.

func (PieSeriesList) SumSeries added in v0.5.0

func (p PieSeriesList) SumSeries() float64

func (PieSeriesList) ToGenericSeriesList added in v0.5.0

func (p PieSeriesList) ToGenericSeriesList() GenericSeriesList

type PieSeriesOption

type PieSeriesOption struct {
	Label SeriesLabel
	Names []string
}

PieSeriesOption provides series customization for NewSeriesListPie.

type Point

type Point = chartdraw.Point

Point represents an X,Y coordinate pair.

type RadarChartOption

type RadarChartOption struct {
	// Theme specifies the colors used for the radar chart.
	Theme ColorPalette
	// Padding specifies the padding around the chart.
	Padding Box
	// Deprecated: Font is deprecated, instead the font needs to be set on the SeriesLabel, or other specific elements.
	Font *truetype.Font
	// SeriesList provides the data population for the chart. Constructed using NewSeriesListRadar.
	SeriesList RadarSeriesList
	// Title contains options for rendering the chart title.
	Title TitleOption
	// Legend contains options for the data legend.
	Legend LegendOption
	// RadarIndicators provides the radar indicator list.
	RadarIndicators []RadarIndicator
	// Radius sets the chart radius. Default is "40%".
	Radius string
	// ValueFormatter defines how float values are rendered to strings, notably for series labels.
	ValueFormatter ValueFormatter
}

RadarChartOption defines the options for rendering a radar chart. Render the chart using Painter.RadarChart.

func NewRadarChartOptionWithData added in v0.4.0

func NewRadarChartOptionWithData(data [][]float64, names []string, values []float64) RadarChartOption

NewRadarChartOptionWithData returns an initialized RadarChartOption with the SeriesList set with the provided data slice.

type RadarIndicator

type RadarIndicator struct {
	// Name specifies a name for the indicator.
	Name string
	// Max is the maximum value of indicator.
	Max float64
	// Min is the minimum value of indicator.
	Min float64
	// FontStyle provides the font configuration for the indicator.
	FontStyle FontStyle
}

RadarIndicator defines the dimensions of a radar chart axis.

func NewRadarIndicators

func NewRadarIndicators(names []string, values []float64) []RadarIndicator

NewRadarIndicators returns a radar indicator list.

type RadarSeries added in v0.5.0

type RadarSeries struct {
	// Values provides the series data list.
	Values []float64
	// Label provides the series labels.
	Label SeriesLabel
	// Name specifies a name for the series.
	Name string
}

RadarSeries references a population of data for radar charts.

type RadarSeriesList added in v0.5.0

type RadarSeriesList []RadarSeries

RadarSeriesList provides the data populations for radar charts (RadarChartOption).

func NewSeriesListRadar added in v0.4.0

func NewSeriesListRadar(values [][]float64, opts ...RadarSeriesOption) RadarSeriesList

NewSeriesListRadar builds a SeriesList for a Radar chart.

func (RadarSeriesList) SetSeriesLabels added in v0.5.6

func (r RadarSeriesList) SetSeriesLabels(label SeriesLabel)

SetSeriesLabels sets the label for all elements in the series.

func (RadarSeriesList) ToGenericSeriesList added in v0.5.0

func (r RadarSeriesList) ToGenericSeriesList() GenericSeriesList

type RadarSeriesOption added in v0.4.0

type RadarSeriesOption struct {
	Label SeriesLabel
	Names []string
}

RadarSeriesOption provides series customization for NewSeriesListRadar.

type ScatterChartOption added in v0.5.0

type ScatterChartOption struct {
	// Theme specifies the colors used for the scatter chart.
	Theme ColorPalette
	// Padding specifies the padding around the chart.
	Padding Box
	// Deprecated: Font is deprecated, instead the font needs to be set on the SeriesLabel, or other specific elements.
	Font *truetype.Font
	// SeriesList provides the data population for the chart. Typically constructed using
	// NewSeriesListScatter or NewSeriesListScatterMultiValue.
	SeriesList ScatterSeriesList
	// XAxis contains options for the x-axis.
	XAxis XAxisOption
	// YAxis contains options for the y-axis. At most two y-axes are supported.
	YAxis []YAxisOption
	// Title contains options for rendering the chart title.
	Title TitleOption
	// Legend contains options for the data legend.
	Legend LegendOption
	// Symbol specifies the default shape for each data point. Default is 'dot'.
	// Options: 'circle', 'dot', 'square', 'diamond'. Can be overridden per series.
	Symbol Symbol // TODO - v0.6 - consider combining symbol with size into a SymbolStyle struct
	// SymbolSize specifies the size for each data point. Default is 2.0.
	SymbolSize float64
	// ValueFormatter defines how float values are rendered to strings, notably for numeric axis labels.
	ValueFormatter ValueFormatter
}

ScatterChartOption defines the options for rendering a scatter chart. Render the chart using Painter.ScatterChart.

func NewScatterChartOptionWithData added in v0.5.0

func NewScatterChartOptionWithData(data [][]float64) ScatterChartOption

NewScatterChartOptionWithData returns an initialized ScatterChartOption with the SeriesList set with the provided data slice.

func NewScatterChartOptionWithSeries added in v0.5.9

func NewScatterChartOptionWithSeries(sl ScatterSeriesList) ScatterChartOption

NewScatterChartOptionWithSeries returns an initialized ScatterChartOption with the provided SeriesList.

type ScatterSeries added in v0.5.0

type ScatterSeries struct {
	// Values provides the series data values.
	Values [][]float64
	// YAxisIndex is the index for the axis, it must be 0 or 1.
	YAxisIndex int
	// Label provides the series labels.
	Label SeriesLabel
	// Name specifies a name for the series.
	Name string
	// MarkLine provides a configuration for mark lines for this series. When using a MarkLine, you will want to
	// configure padding to the chart on the right for the values.
	MarkLine SeriesMarkLine
	// TrendLine provides configurations for trend lines for this series.
	TrendLine []SeriesTrendLine
	// Symbol specifies a custom symbol for the series.
	Symbol Symbol // TODO - v0.6 - consider combining symbol with size into a SymbolStyle struct
	// contains filtered or unexported fields
}

ScatterSeries references a population of data for scatter charts.

func (*ScatterSeries) Summary added in v0.5.0

func (s *ScatterSeries) Summary() populationSummary

type ScatterSeriesList added in v0.5.0

type ScatterSeriesList []ScatterSeries

ScatterSeriesList provides the data populations for scatter charts (ScatterChartOption).

func NewSeriesListScatter added in v0.5.0

func NewSeriesListScatter(values [][]float64, opts ...ScatterSeriesOption) ScatterSeriesList

NewSeriesListScatter builds a SeriesList for a scatter chart. The first dimension of the values indicates the population of the data, while the second dimension provides the samples for the population.

func NewSeriesListScatterMultiValue added in v0.5.0

func NewSeriesListScatterMultiValue(values [][][]float64, opts ...ScatterSeriesOption) ScatterSeriesList

NewSeriesListScatterMultiValue builds a SeriesList for a scatter charts. The first dimension of the values indicates the population of the data, while the second dimension provides the samples for the population. Multiple values for a single sample can be provided using the last dimension.

func (ScatterSeriesList) SetSeriesLabels added in v0.5.6

func (s ScatterSeriesList) SetSeriesLabels(label SeriesLabel)

SetSeriesLabels sets the label for all elements in the series.

func (ScatterSeriesList) SumSeries added in v0.5.0

func (s ScatterSeriesList) SumSeries() []float64

SumSeries returns a float64 slice with the sum of each series.

func (ScatterSeriesList) ToGenericSeriesList added in v0.5.6

func (s ScatterSeriesList) ToGenericSeriesList() GenericSeriesList

type ScatterSeriesOption added in v0.5.0

type ScatterSeriesOption struct {
	Label     SeriesLabel
	Names     []string
	MarkLine  SeriesMarkLine
	TrendLine []SeriesTrendLine
}

ScatterSeriesOption provides series customization for NewSeriesListScatter and NewSeriesListScatterMultiValue.

type SeriesLabel

type SeriesLabel struct {
	// Show controls whether data labels are displayed for this series.
	// Use Ptr(true) to show labels, Ptr(false) to hide them, or nil for chart-specific defaults.
	Show *bool
	// LabelFormatter provides complete control over label content and per-point styling.
	// When set, this takes precedence for label production.
	LabelFormatter SeriesLabelFormatter
	// Deprecated: FormatTemplate is deprecated, use LabelFormatter instead for better control.
	// Template string for formatting data labels with placeholders:
	//   {b}: the name of the data item
	//   {c}: the value of the data item
	//   {d}: the percentage of the data item (pie/doughnut charts only)
	// Example: "{b}: {c} ({d})" produces "Sales: 150 (25%)"
	FormatTemplate string
	// ValueFormatter functions as the simplest method of number formatting or customization.
	// Only utilized when other methods are not set.
	ValueFormatter ValueFormatter
	// FontStyle specifies the default font styling for labels in this series.
	// Individual labels can override this via LabelFormatter's LabelStyle return value.
	FontStyle FontStyle
	// Distance specifies the pixel distance between the label and its associated data point or chart element.
	Distance int // TODO - do we want to replace with just Offset?
	// Offset specifies an offset from the position.
	Offset OffsetInt
}

SeriesLabel configures how individual data point labels are rendered on charts.

type SeriesLabelFormatter added in v0.5.16

type SeriesLabelFormatter func(index int, name string, val float64) (string, *LabelStyle)

SeriesLabelFormatter is a function that generates custom labels with optional per-point styling. This provides full control over label content and appearance for each data point.

Parameters:

  • index: The data point index within the series
  • name: The series name for this data point
  • val: The numeric value for this data point

Returns:

  • string: The label text to display. Return "" to hide the label for this point
  • *LabelStyle: Optional styling override for this specific label. Return nil to use default series/theme styling.

func LabelFormatterGradientColor added in v0.5.16

func LabelFormatterGradientColor(values []float64, colors ...Color) SeriesLabelFormatter

LabelFormatterGradientColor returns a SeriesLabelFormatter that colors labels with a gradient between multiple colors. The minimum value gets the first color, maximum value gets the last color, and intermediate values are interpolated. For two colors: lowColor -> highColor. For three+ colors: first -> second -> ... -> last. This formatter requires the complete data values to determine the min/max range for color interpolation.

func LabelFormatterGradientGreenRed added in v0.5.16

func LabelFormatterGradientGreenRed(values []float64) SeriesLabelFormatter

LabelFormatterGradientGreenRed returns a SeriesLabelFormatter that colors labels from green (minimum) to red (maximum). This formatter requires the complete data values to determine the min/max range for color interpolation.

func LabelFormatterGradientRedGreen added in v0.5.16

func LabelFormatterGradientRedGreen(values []float64) SeriesLabelFormatter

LabelFormatterGradientRedGreen returns a SeriesLabelFormatter that colors labels from red (minimum) to green (maximum). This formatter requires the complete data values to determine the min/max range for color interpolation.

func LabelFormatterThresholdMax added in v0.5.16

func LabelFormatterThresholdMax(threshold float64) SeriesLabelFormatter

LabelFormatterThresholdMax returns a SeriesLabelFormatter that only shows labels for values at or below the specified threshold. Values above the threshold will have empty labels (effectively hiding them).

func LabelFormatterThresholdMin added in v0.5.16

func LabelFormatterThresholdMin(threshold float64) SeriesLabelFormatter

LabelFormatterThresholdMin returns a SeriesLabelFormatter that only shows labels for values above the specified threshold. Values at or below the threshold will have empty labels (effectively hiding them).

func LabelFormatterTopN added in v0.5.16

func LabelFormatterTopN(values []float64, n int) SeriesLabelFormatter

LabelFormatterTopN returns a SeriesLabelFormatter that only shows labels for the top N highest values in the provided slice. This formatter requires the complete data values to determine which values are in the top N.

type SeriesMark added in v0.5.0

type SeriesMark struct {
	// Type is the mark data type: "max", "min", "average". "average" is only for mark line.
	Type string
	// Global specifies the mark references the sum of all series. Only used when
	// the Series is "Stacked" and the mark is on the LAST Series of the SeriesList.
	Global bool
}

SeriesMark describes a single mark line or point type.

type SeriesMarkLine

type SeriesMarkLine struct {
	// ValueFormatter is used to produce the label for the Mark Line.
	ValueFormatter ValueFormatter
	// Lines are the mark lines for the series.
	Lines SeriesMarkList
}

SeriesMarkLine configures mark lines for a series.

func NewMarkLine

func NewMarkLine(markLineTypes ...string) SeriesMarkLine

NewMarkLine returns a mark line for the provided types. Set on a specific Series instance.

func (*SeriesMarkLine) AddGlobalLines added in v0.5.0

func (m *SeriesMarkLine) AddGlobalLines(markTypes ...string)

AddGlobalLines adds "global" mark lines, which reference the sum of all series. These marks are only rendered when the Series is "Stacked" and the mark line is on the LAST Series of the SeriesList.

func (*SeriesMarkLine) AddLines added in v0.5.0

func (m *SeriesMarkLine) AddLines(markTypes ...string)

AddLines adds mark lines for the series.

type SeriesMarkList added in v0.5.0

type SeriesMarkList []SeriesMark

SeriesMarkList is a slice of SeriesMark values.

func NewSeriesMarkGlobalList added in v0.5.0

func NewSeriesMarkGlobalList(markTypes ...string) SeriesMarkList

NewSeriesMarkGlobalList returns a slice of SeriesMark initialized for the given types with the global flag set. Global marks reference the sum of all series. Only used when the Series is "Stacked" and the mark is on the LAST Series of the SeriesList.

func NewSeriesMarkList added in v0.5.0

func NewSeriesMarkList(markTypes ...string) SeriesMarkList

NewSeriesMarkList returns a SeriesMarkList initialized for the given types.

type SeriesMarkPoint

type SeriesMarkPoint struct {
	// SymbolSize is the width of symbol, default value is 28.
	SymbolSize int
	// ValueFormatter is used to produce the label for the Mark Point.
	ValueFormatter ValueFormatter
	// Points are the mark points for the series.
	Points SeriesMarkList
}

SeriesMarkPoint configures mark points for a series.

func NewMarkPoint

func NewMarkPoint(markPointTypes ...string) SeriesMarkPoint

NewMarkPoint returns a mark point for the provided types. Set on a specific Series instance.

func (*SeriesMarkPoint) AddGlobalPoints added in v0.5.0

func (m *SeriesMarkPoint) AddGlobalPoints(markTypes ...string)

AddGlobalPoints adds "global" mark points, which reference the sum of all series. These marks are only rendered when the Series is "Stacked" and the mark point is on the LAST Series of the SeriesList.

func (*SeriesMarkPoint) AddPoints added in v0.5.0

func (m *SeriesMarkPoint) AddPoints(markTypes ...string)

AddPoints adds mark points for the series.

type SeriesTrendLine added in v0.5.0

type SeriesTrendLine struct {
	// LineStrokeWidth is the width of the rendered line.
	LineStrokeWidth float64
	// StrokeSmoothingTension should be between 0 and 1. At 0 lines are sharp and precise, 1 provides smoother lines.
	StrokeSmoothingTension float64
	// LineColor overrides the theme color for this trend line.
	LineColor Color
	// DashedLine indicates if the trend line will be a dashed line. Default depends on chart type.
	DashedLine *bool
	// Type specifies the trend line type: "linear", "cubic", "sma", "ema", "rsi".
	Type string
	// Deprecated: Window is deprecated, use Period instead.
	Window int
	// Period specifies the number of data points to consider for trend calculations.
	// Used by moving averages (SMA, EMA), Bollinger Bands, RSI, and other indicators.
	// For example, Period=20 calculates a 20-period moving average.
	Period int
}

SeriesTrendLine describes the rendered trend line style.

func NewTrendLine added in v0.5.0

func NewTrendLine(trendType string) []SeriesTrendLine

NewTrendLine returns a trend line for the provided type. Set on a specific Series instance.

type Symbol added in v0.4.9

type Symbol string

Symbol defines the shape used for data points and legends.

type TableCell

type TableCell struct {
	// Text is the text content of the table cell.
	Text string
	// FontStyle contains the font configuration for the cell text.
	FontStyle FontStyle
	// FillColor sets the background color for this table cell.
	FillColor Color
	// Row is the row index of the table cell.
	Row int
	// Column is the column index of the table cell.
	Column int
}

TableCell represents a single cell in a table.

type TableChartOption

type TableChartOption struct {
	// OutputFormat specifies the output type: "svg", "png", "jpg".
	OutputFormat string
	// Theme specifies the colors used for the table.
	Theme ColorPalette
	// Padding specifies the padding around the table.
	Padding Box
	// Width specifies the width of the table.
	Width int
	// Header provides header data for the top of the table.
	Header []string
	// Data provides the row and column data for the table.
	Data [][]string
	// Spans provides the column span for each column.
	Spans []int
	// TextAligns specifies the text alignment for each cell.
	TextAligns []string
	// FontStyle contains the font configuration for table text.
	FontStyle FontStyle
	// HeaderBackgroundColor provides the background color for the header row.
	HeaderBackgroundColor Color
	// HeaderFontColor specifies the text color for header text.
	HeaderFontColor Color
	// RowBackgroundColors specifies the background colors for each row.
	RowBackgroundColors []Color
	// BackgroundColor specifies the general background color.
	BackgroundColor Color
	// CellModifier is an optional function to modify TableCell style or content before rendering.
	CellModifier func(TableCell) TableCell
}

TableChartOption defines options for rendering a table chart.

type ThemeOption

type ThemeOption struct {
	// IsDarkMode indicates whether the theme is designed for dark backgrounds, affecting color adjustments and text visibility.
	IsDarkMode bool
	// AxisStrokeColor is the default stroke color for both axes.
	AxisStrokeColor Color
	// XAxisStrokeColor overrides AxisStrokeColor for the x-axis.
	XAxisStrokeColor Color
	// YAxisStrokeColor overrides AxisStrokeColor for the y-axis.
	YAxisStrokeColor Color
	// AxisSplitLineColor sets the color of grid lines drawn between ticks.
	AxisSplitLineColor Color
	// BackgroundColor sets the chart background.
	BackgroundColor Color
	// TextColor is the default font color applied if specific text colors are unset.
	TextColor Color
	// TextColorTitle sets the title text color.
	TextColorTitle Color
	// TextColorMark sets the color of mark line and point labels.
	TextColorMark Color
	// TextColorLabel defines the color of series labels.
	TextColorLabel Color
	// TextColorLegend defines the legend text color.
	TextColorLegend Color
	// TextColorXAxis defines the x-axis label text color.
	TextColorXAxis Color
	// TextColorYAxis defines the y-axis label text color.
	TextColorYAxis Color
	// TitleBorderColor draws an optional border around the title.
	TitleBorderColor Color
	// LegendBorderColor draws an optional border around the legend.
	LegendBorderColor Color
	// SeriesColors provides the color palette used for series data.
	SeriesColors []Color
	// SeriesTrendColors provides the palette for rendered trend lines.
	SeriesTrendColors []Color
	// CandleWickColor is the color for the high-low wicks. If not set, uses body color.
	CandleWickColor Color
	// SeriesUpDownColors provides distinct up/down (bear/bull) color pairs for each series.
	SeriesUpDownColors [][2]Color
}

ThemeOption defines color options for a theme.

type TitleOption

type TitleOption struct {
	// Show specifies if the title should be rendered. Set to *false (via Ptr(false)) to hide the title.
	Show *bool
	// Theme specifies the colors used for the title.
	Theme ColorPalette
	// Text is the title text. Supports '\n' for line breaks.
	Text string
	// Subtext is additional text below the title. Supports '\n' for line breaks.
	Subtext string
	// Offset specifies the position of the title relative to the left and top sides.
	Offset OffsetStr
	// FontStyle specifies the font, size, and style for the title text.
	FontStyle FontStyle
	// SubtextFontStyle specifies the font, size, and style for the subtext.
	SubtextFontStyle FontStyle
	// BorderWidth can be set to a non-zero value to render a box around the title.
	BorderWidth float64
}

TitleOption configures rendering of a chart title.

type ValueFormatter

type ValueFormatter func(float64) string

ValueFormatter defines a function that formats numeric values into string representations for display on charts.

type XAxisOption

type XAxisOption struct {
	// Show specifies if the x-axis should be rendered. Set to *false (via Ptr(false)) to hide the axis.
	Show *bool
	// Theme specifies the colors used for the x-axis.
	Theme ColorPalette
	// Title specifies a name for the axis. If set, the title is rendered below the x-axis.
	Title string
	// TitleFontStyle specifies the font, size, and color for the axis title.
	TitleFontStyle FontStyle
	// Labels provides labels for each value on the x-axis. Indices must match series data indices.
	Labels []string
	// DataStartIndex specifies the starting index for data values.
	DataStartIndex int
	// Deprecated: Position is deprecated. Currently, when set to `bottom` and the labels would render on the top
	// side of the axis line. However, the line would remain at the bottom of the chart. This seems confusing, and
	// attempts to actually move the axis line to the top of the chart are currently very messy looking. For that
	// reason this is currently deprecated. If a top x-Axis is valuable to you, please open a feature request.
	Position string
	// BoundaryGap specifies that the chart should have additional space on the left and right, with data points being
	// centered between two axis ticks. Default is set based on the dataset density / size to produce an easy-to-read
	// graph. Specify a *bool (through charts.Ptr(false) or charts.Ptr(true)) to enforce a spacing.
	BoundaryGap *bool
	// Deprecated: FontStyle is deprecated, use LabelFontStyle.
	FontStyle FontStyle
	// LabelFontStyle specifies the font configuration for each label.
	LabelFontStyle FontStyle
	// LabelRotation is the rotation angle in radians for labels. Use DegreesToRadians(float64) to convert from degrees.
	LabelRotation float64
	// LabelOffset is the position offset for each label.
	LabelOffset OffsetInt
	// ValueFormatter defines how float values are rendered to strings, notably for numeric axis labels.
	ValueFormatter ValueFormatter
	// Unit suggests the axis step size (recommendation only). Larger values result in fewer labels.
	Unit float64
	// LabelCount is the number of labels to show on the axis. Use a smaller count to reduce text collisions.
	LabelCount int
	// LabelCountAdjustment specifies a relative influence on how many labels should be rendered.
	// Typically, this is negative to result in cleaner graphs, positive values may result in text collisions.
	LabelCountAdjustment int
}

XAxisOption configures the horizontal axis.

type YAxisOption

type YAxisOption struct {
	// Show specifies if the y-axis should be rendered. Set to *false (via Ptr(false)) to hide the axis.
	Show *bool
	// Theme specifies the colors used for the y-axis.
	Theme ColorPalette
	// Title specifies a name for the axis. If set, the axis name is rendered on the outside of the y-Axis.
	Title string
	// TitleFontStyle specifies the font, size, and color for the axis title.
	TitleFontStyle FontStyle
	// Min forces the minimum value of the y-axis when set (Use Ptr(float64)).
	Min *float64
	// Max forces the maximum value of the y-axis when set (Use Ptr(float64)).
	Max *float64
	// RangeValuePaddingScale suggests a padding scale to apply to the max and min values.
	RangeValuePaddingScale *float64
	// Labels provides labels for each value on the y-axis.
	Labels []string
	// Position describes the y-axis position: 'left' or 'right'.
	Position string
	// Deprecated: FontStyle is deprecated, use LabelFontStyle.
	FontStyle FontStyle
	// LabelFontStyle specifies the font configuration for each label.
	LabelFontStyle FontStyle
	// LabelRotation is the rotation angle in radians for labels. Use DegreesToRadians(float64) to convert from degrees.
	LabelRotation float64
	// Deprecated: Formatter is deprecated, use ValueFormatter instead.
	Formatter string
	// Unit suggests the axis step size (recommendation only). Larger values result in fewer labels.
	Unit float64
	// LabelCount is the number of labels to show on the axis. Use a smaller count to reduce text collisions.
	LabelCount int
	// LabelCountAdjustment specifies relative influence on label count.
	// Negative values result in cleaner graphs; positive values may cause text collisions.
	LabelCountAdjustment int
	// LabelSkipCount specifies a qty of lines between labels that show only horizontal lines without labels.
	LabelSkipCount int
	// SplitLineShow when set to *true shows horizontal axis split lines.
	SplitLineShow *bool
	// SpineLineShow controls whether the vertical spine line is shown.
	// Default is hidden unless it's a category axis.
	SpineLineShow *bool
	// ValueFormatter defines how float values are rendered to strings, notably for numeric axis labels.
	ValueFormatter ValueFormatter
	// contains filtered or unexported fields
}

YAxisOption configures the vertical axis.

Directories

Path Synopsis
examples command
examples/axes command
examples/basic command
examples/legend command
examples
demo/themes command

Jump to

Keyboard shortcuts

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