charts

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2025 License: MIT Imports: 15 Imported by: 0

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 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.

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 early improvements in our fork include:

  • Axis Improvements: Significant enhancements to axis rendering, data range selection, and configuration simplification were made in PR #3.
  • Theming: In PR #4 (and some subsequent changes) we introduced vivid-light and vivid-dark themes for more vibrant visualizations, alongside API changes for greater theme and font control. Long term we plan to make themes easier to mutate and define.
  • Configuration Simplification: PR #5 began our effort to streamline chart configuration, making names more descriptive and specific while focusing on a theme-centric approach. Documentation on configuration and use is also being improved. (See also #15, #20)
  • Expanded Testing: Ongoing test coverage expansions have led to bug discoveries and fixes. This will continue to help ensure that our charts render perfectly for a wide range of configurations and use.

Our library is a work in progress, 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 are a former user of wcharczuk/go-chart, you should be able to use this project with reasonable changes. The wcharczuk/go-chart project was forked under our chartdraw package. Any code changes necessary are documented on our wcharczuk/go‐chart Migration Guide.

Functionality

Chart Types

These chart types are supported: line, bar, horizontal bar, pie, radar or funnel and table.

Please see the ./examples/ directory and the README within it to see a variety of implementations of our different chart types and configurations.

Themes

Our built in themes are: light, dark, vivid-light, vivid-dark, ant, grafana

themes

Line Chart
Line Chart
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{
		{
			120,
			132,
			101,
			134,
			90,
			230,
			210,
		},
		{
			// specify values for additional data series
		},
	}
	p, err := charts.LineRender(
		values,
		charts.TitleTextOptionFunc("Line Chart Demo"),
		charts.XAxisDataOptionFunc([]string{
			"Mon",	// notice the 7 labels here match to the 7 samples above
			"Tue",
			"Wed",
			"Thu",
			"Fri",
			"Sat",
			"Sun",
		}),
		charts.LegendLabelsOptionFunc([]string{
			"Email",
			"Search Engine",
		}),
		// other options as desired...
Bar Chart
Bar Chart
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{
		{
			2.0,
			4.9,
			7.0,
			23.2,
			25.6,
			76.7,
			135.6,
			162.2,
			32.6,
			20.0,
			6.4,
			3.3,
		},
		{
			// snip...	
		},
	}
	p, err := charts.BarRender(
		values,
		charts.XAxisDataOptionFunc([]string{
			"Jan",
			"Feb",
			"Mar",
			"Apr",
			"May",
			"Jun",
			"Jul",
			"Aug",
			"Sep",
			"Oct",
			"Nov",
			"Dec",
		}),
		charts.LegendLabelsOptionFunc([]string{
			"Rainfall",
			"Evaporation",
		}),
		charts.MarkLineOptionFunc(0, charts.SeriesMarkDataTypeAverage),
		charts.MarkPointOptionFunc(0, charts.SeriesMarkDataTypeMax,
			charts.SeriesMarkDataTypeMin),
		// custom option func
		func(opt *charts.ChartOption) {
			opt.SeriesList[1].MarkPoint = charts.NewMarkPoint(
				charts.SeriesMarkDataTypeMax,
				charts.SeriesMarkDataTypeMin,
			)
			opt.SeriesList[1].MarkLine = charts.NewMarkLine(
				charts.SeriesMarkDataTypeAverage,
			)
		},
		// other options as desired...
Horizontal Bar Chart
Horizontal Bar Chart
import (
	"github.com/go-analyze/charts"
)

func main() {
	values := [][]float64{
		{
			18203,
			23489,
			29034,
			104970,
			131744,
			630230,
		},
		{
			// snip...	
		},
	}
	p, err := charts.HorizontalBarRender(
		values,
		charts.TitleTextOptionFunc("World Population"),
		charts.PaddingOptionFunc(charts.Box{
			Top:    20,
			Right:  40,
			Bottom: 20,
			Left:   20,
		}),
		charts.LegendLabelsOptionFunc([]string{
			"2011",
			"2012",
		}),
		charts.YAxisDataOptionFunc([]string{
			"Brazil",
			"Indonesia",
			"USA",
			"India",
			"China",
			"World",
		}),
		// other options as desired...
Pie Chart
Pie Chart
import (
	"github.com/go-analyze/charts"
)

func main() {
	values := []float64{
		1048,
		735,
		580,
		484,
		300,
	}
	p, err := charts.PieRender(
		values,
		charts.TitleOptionFunc(charts.TitleOption{
			Text:    "Rainfall vs Evaporation",
			Subtext: "Fake Data",
			Offset:  charts.OffsetCenter,
		}),
		charts.LegendOptionFunc(charts.LegendOption{
			Data: []string{
				"Search Engine",
				"Direct",
				"Email",
				"Union Ads",
				"Video Ads",
			},
		}),
		charts.PieSeriesShowLabel(),
		// other options as desired...
Radar Chart
Radar Chart
import (
	"github.com/go-analyze/charts"
)

func main() {
	values := [][]float64{
		{
			4200,
			3000,
			20000,
			35000,
			50000,
			18000,
		},
		{
			// snip...
		},
	}
	p, err := charts.RadarRender(
		values,
		charts.TitleTextOptionFunc("Basic Radar Chart"),
		charts.LegendLabelsOptionFunc([]string{
			"Allocated Budget",
			"Actual Spending",
		}),
		charts.RadarIndicatorOptionFunc([]string{
			"Sales",
			"Administration",
			"Information Technology",
			"Customer Support",
			"Development",
			"Marketing",
		}, []float64{
			6500,
			16000,
			30000,
			38000,
			52000,
			25000,
		}),
		// other options as desired...
Table
Table
import (
	"github.com/go-analyze/charts"
)

func main() {
	header := []string{
		"Name",
		"Age",
		"Address",
		"Tag",
		"Action",
	}
	data := [][]string{
		{
			"John Brown",
			"32",
			"New York No. 1 Lake Park",
			"nice, developer",
			"Send Mail",
		},
		{
			"Jim Green	",
			"42",
			"London No. 1 Lake Park",
			"wow",
			"Send Mail",
		},
		{
			"Joe Black	",
			"32",
			"Sidney No. 1 Lake Park",
			"cool, teacher",
			"Send Mail",
		},
	}
	spans := map[int]int{
		0: 2,
		1: 1,
		2: 3,
		3: 2,
		4: 2,
	}
	p, err := charts.TableRender(
		header,
		data,
		spans,
	)
	// snip...
Funnel Chart
import (
	"github.com/go-analyze/charts"
)

func main() {
	values := []float64{
		100,
		80,
		60,
		40,
		20,
	}
	p, err := charts.FunnelRender(
		values,
		charts.TitleTextOptionFunc("Funnel"),
		charts.LegendLabelsOptionFunc([]string{
			"Show",
			"Click",
			"Visit",
			"Inquiry",
			"Order",
		}),
	)
	// snip...
ECharts Render
import (
	"github.com/go-analyze/charts"
)

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

Documentation

Index

Constants

View Source
const (
	ChartTypeLine          = "line"
	ChartTypeBar           = "bar"
	ChartTypePie           = "pie"
	ChartTypeRadar         = "radar"
	ChartTypeFunnel        = "funnel"
	ChartTypeHorizontalBar = "horizontalBar"
)
View Source
const (
	ChartOutputSVG = "svg"
	ChartOutputPNG = "png"
)
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 (
	SeriesMarkDataTypeMax     = "max"
	SeriesMarkDataTypeMin     = "min"
	SeriesMarkDataTypeAverage = "average"
)
View Source
const IconDot = "dot"
View Source
const IconRect = "rect"
View Source
const ThemeAnt = "ant"

ThemeAnt is an ant styled theme.

View Source
const ThemeDark = "dark"

ThemeDark is a dark alternative to the default theme 'light, with series colors from echarts'.

View Source
const ThemeGrafana = "grafana"

ThemeGrafana is a grafana styled theme.

View Source
const ThemeLight = "light"

ThemeLight is the default theme used, with series colors from echarts.

View Source
const ThemeVividDark = "vivid-dark"

ThemeVividDark is a dark alternative to 'ThemeVividLight', with the same bright initial series colors.

View Source
const ThemeVividLight = "vivid-light"

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.

Variables

View Source
var BoxZero = chartdraw.BoxZero
View Source
var OffsetCenter = OffsetStr{Left: PositionCenter}
View Source
var OffsetLeft = OffsetStr{Left: PositionLeft}
View Source
var OffsetRight = OffsetStr{Left: PositionRight}

Functions

func BoolPointer

func BoolPointer(b bool) *bool

BoolPointer returns a pointer to the given bool value, useful for configuration.

func False

func False() *bool

False returns a pointer to a false bool, useful for configuration.

func FloatPointer

func FloatPointer(f float64) *float64

FloatPointer returns a pointer to the given float64 value, useful for configuration.

func FormatValueHumanize added in v0.3.1

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

FormatValueHumanize takes in a value and a specified precision, rounding to the specified precision and returning a human friendly number string including commas.

func FormatValueHumanizeShort added in v0.3.1

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

FormatValueHumanizeShort takes in a value and a specified precision, rounding to the specified precision and returning a human friendly number string including commas. If the value is over 1,000 it will be reduced to a shorter version with the appropriate k, M, G, T suffix.

func GetDefaultFont

func GetDefaultFont() *truetype.Font

GetDefaultFont get default font.

func GetFont

func GetFont(fontFamily string) *truetype.Font

GetFont get the font by font family or the default if the family is not installed.

func GetNullValue

func GetNullValue() float64

GetNullValue gets the null value

func InstallFont

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

InstallFont installs the font for charts

func InstallTheme

func InstallTheme(name string, opt ThemeOption)

InstallTheme adds a theme to the catalog which can later be retrieved using GetTheme.

func RenderEChartsToPNG

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

func RenderEChartsToSVG

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

func SetDefaultChartDimensions added in v0.4.0

func SetDefaultChartDimensions(width, height int)

SetDefaultChartDimensions sets default width and height of charts if not otherwise specified in their configuration.

func SetDefaultFont

func SetDefaultFont(fontFamily string) error

SetDefaultFont set default font by name.

func SetDefaultTheme

func SetDefaultTheme(name string) error

SetDefaultTheme sets default theme by name.

func True

func True() *bool

True returns a pointer to a true bool, useful for configuration.

Types

type BarChartOption

type BarChartOption struct {
	// Theme specifies the colors used for the bar chart.
	Theme ColorPalette
	// Padding specifies the padding of bar chart.
	Padding Box
	// Font is the font used to render the chart.
	Font *truetype.Font
	// SeriesList provides the data series.
	SeriesList SeriesList
	// XAxis are options for the x-axis.
	XAxis XAxisOption
	// YAxis are options for the y-axis (at most two).
	YAxis []YAxisOption
	// Title are options for rendering the title.
	Title TitleOption
	// Legend are options for the data legend.
	Legend LegendOption
	// BarWidth specifies the width of each bar.
	BarWidth int
	// RoundedBarCaps set to `true` to produce a bar graph where the bars have rounded tops.
	RoundedBarCaps *bool
	// ValueFormatter defines how float values should be rendered to strings, notably for numeric axis labels.
	ValueFormatter ValueFormatter
}

func NewBarChartOptionWithData added in v0.4.0

func NewBarChartOptionWithData(data [][]float64) BarChartOption

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

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

type ChartOption

type ChartOption struct {
	// OutputFormat specifies the output type of chart, "svg" or "png", default value is "png".
	OutputFormat string
	// Width is the width of chart, default width is 600.
	Width int
	// Height is the height of chart, default height is 400.
	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 chart, default padding is [20, 10, 10, 10].
	Padding Box
	// XAxis are options for the x-axis.
	XAxis XAxisOption
	// YAxis are options for the y-axis (at most two).
	YAxis []YAxisOption
	// Title are options for rendering the title.
	Title TitleOption
	// Legend are options for the data legend.
	Legend LegendOption
	// Font is the font to use for rendering the chart.
	Font *truetype.Font
	// Box specifies the canvas box for the chart.
	Box Box
	// SeriesList provides the data series.
	SeriesList SeriesList
	// RadarIndicators are radar indicator list for radar charts.
	RadarIndicators []RadarIndicator
	// SymbolShow set this to *false or *true (using False() or True()) to force if the symbols should be shown or hidden.
	SymbolShow *bool
	// LineStrokeWidth is the stroke width for line charts.
	LineStrokeWidth float64
	// FillArea set to true to fill the area under the line in line charts
	FillArea bool
	// FillOpacity is the opacity (alpha) of the area fill in line charts.
	FillOpacity uint8
	// BarWidth is the width of the bars for bar charts.
	BarWidth int
	// BarHeight is the height of the bars for horizontal bar charts.
	BarHeight int
	// Children are Child charts to render together.
	Children []ChartOption

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

type Color

type Color = drawing.Color

func ParseColor added in v0.3.2

func ParseColor(color string) Color

ParseColor parses a color from a string. The color can be specified in hex with a `#` prefix (for example '#313233'), in rgb(i,i,i) or rgba(i,i,i,f) format, or as a common name (for example 'red').

type ColorPalette

type ColorPalette interface {
	IsDark() bool
	GetAxisStrokeColor() Color
	GetAxisSplitLineColor() Color
	GetSeriesColor(int) Color
	GetBackgroundColor() Color
	GetTextColor() Color
	// WithAxisColor will provide a new ColorPalette that uses the specified color for axis values.
	// This includes the Axis Stroke, Split Line, and Text Color.
	WithAxisColor(Color) ColorPalette
	// WithTextColor will provide a new ColorPalette that uses the specified color for text.
	// This is generally recommended over using the FontColor config values.
	WithTextColor(Color) ColorPalette
	// WithSeriesColors will provide a new ColorPalette that uses the specified series colors.
	WithSeriesColors([]Color) ColorPalette
	// WithBackgroundColor will provide a new ColorPalette that uses the specified color for the background.
	WithBackgroundColor(Color) ColorPalette
}

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 the theme is not installed.

func MakeTheme

func MakeTheme(opt ThemeOption) ColorPalette

MakeTheme constructs a one-off theme without installing it into the catalog.

type EChartStyle

type EChartStyle struct {
	Color string `json:"color"`
}

type EChartsAxisLabel

type EChartsAxisLabel struct {
	Formatter string `json:"formatter"`
}

type EChartsLabelOption

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

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"`
	Left      EChartsPosition  `json:"left"`
	Top       EChartsPosition  `json:"top"`
	TextStyle EChartsTextStyle `json:"textStyle"`
}

type EChartsMarkData

type EChartsMarkData struct {
	Type string `json:"type"`
}

func (*EChartsMarkData) UnmarshalJSON

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

type EChartsMarkLine

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

func (*EChartsMarkLine) ToSeriesMarkLine

func (eml *EChartsMarkLine) ToSeriesMarkLine() SeriesMarkLine

type EChartsMarkPoint

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

func (*EChartsMarkPoint) ToSeriesMarkPoint

func (emp *EChartsMarkPoint) ToSeriesMarkPoint() SeriesMarkPoint

type EChartsOption

type EChartsOption struct {
	Type       string         `json:"type"`
	Theme      string         `json:"theme"`
	FontFamily string         `json:"fontFamily"`
	Padding    EChartsPadding `json:"padding"`
	Box        chartdraw.Box  `json:"box"`
	Width      int            `json:"width"`
	Height     int            `json:"height"`
	Title      struct {
		Text         string           `json:"text"`
		Subtext      string           `json:"subtext"`
		Left         EChartsPosition  `json:"left"`
		Top          EChartsPosition  `json:"top"`
		TextStyle    EChartsTextStyle `json:"textStyle"`
		SubtextStyle EChartsTextStyle `json:"subtextStyle"`
	} `json:"title"`
	XAxis  EChartsXAxis  `json:"xAxis"`
	YAxis  EChartsYAxis  `json:"yAxis"`
	Legend EChartsLegend `json:"legend"`
	Radar  struct {
		Indicator []RadarIndicator `json:"indicator"`
	} `json:"radar"`
	Series   EChartsSeriesList `json:"series"`
	Children []EChartsOption   `json:"children"`
}

func (*EChartsOption) ToOption

func (eo *EChartsOption) ToOption() ChartOption

type EChartsPadding

type EChartsPadding struct {
	Box chartdraw.Box
}

func (*EChartsPadding) UnmarshalJSON

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

type EChartsPosition

type EChartsPosition string

func (*EChartsPosition) UnmarshalJSON

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

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"`
	// label configuration
	Label     EChartsLabelOption `json:"label"`
	MarkPoint EChartsMarkPoint   `json:"markPoint"`
	MarkLine  EChartsMarkLine    `json:"markLine"`
	Max       *float64           `json:"max"`
	Min       *float64           `json:"min"`
}

type EChartsSeriesData

type EChartsSeriesData struct {
	Value     EChartsSeriesDataValue `json:"value"`
	Name      string                 `json:"name"`
	ItemStyle EChartStyle            `json:"itemStyle"`
}

func (*EChartsSeriesData) UnmarshalJSON

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

type EChartsSeriesDataValue

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

func (*EChartsSeriesDataValue) First

func (value *EChartsSeriesDataValue) First() float64

func (*EChartsSeriesDataValue) UnmarshalJSON

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

type EChartsSeriesList

type EChartsSeriesList []EChartsSeries

func (EChartsSeriesList) ToSeriesList

func (esList EChartsSeriesList) ToSeriesList() SeriesList

type EChartsTextStyle

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

func (*EChartsTextStyle) ToStyle

func (et *EChartsTextStyle) ToStyle() chartdraw.Style

type EChartsXAxis

type EChartsXAxis struct {
	Data []EChartsXAxisData
}

func (*EChartsXAxis) UnmarshalJSON

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

type EChartsXAxisData

type EChartsXAxisData struct {
	BoundaryGap *bool    `json:"boundaryGap"`
	SplitNumber int      `json:"splitNumber"`
	Data        []string `json:"data"`
	Type        string   `json:"type"`
}

type EChartsYAxis

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

func (*EChartsYAxis) UnmarshalJSON

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

type EChartsYAxisData

type EChartsYAxisData struct {
	Min       *float64         `json:"min"`
	Max       *float64         `json:"max"`
	AxisLabel EChartsAxisLabel `json:"axisLabel"`
	AxisLine  struct {
		LineStyle struct {
			Color string `json:"color"`
		} `json:"lineStyle"`
	} `json:"axisLine"`
	Data []string `json:"data"`
}

type FontStyle added in v0.2.0

type FontStyle = chartdraw.FontStyle

type FunnelChartOption

type FunnelChartOption struct {
	// Theme specifies the colors used for the chart.
	Theme ColorPalette
	// Padding specifies the padding of funnel chart.
	Padding Box
	// Font is the font used to render the chart.
	Font *truetype.Font
	// SeriesList provides the data series.
	SeriesList SeriesList
	// Title are options for rendering the title.
	Title TitleOption
	// Legend are options for the data legend.
	Legend LegendOption
}

func NewFunnelChartOptionWithData added in v0.4.0

func NewFunnelChartOptionWithData(data []float64) FunnelChartOption

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

type FunnelSeriesOption added in v0.4.0

type FunnelSeriesOption struct {
	Label SeriesLabel
	Names []string
}

FunnelSeriesOption provides series customization for NewSeriesListFunnel.

type HorizontalBarChartOption

type HorizontalBarChartOption struct {
	// Theme specifies the colors used for the chart.
	Theme ColorPalette
	// Padding specifies the padding of bar chart.
	Padding Box
	// Font is the font used to render the chart.
	Font *truetype.Font
	// SeriesList provides the data series.
	SeriesList SeriesList
	// XAxis are options for the x-axis.
	XAxis XAxisOption
	// YAxis are options for the y-axis (at most two).
	YAxis []YAxisOption
	// Title are options for rendering the title.
	Title TitleOption
	// Legend are options for the data legend.
	Legend LegendOption
	// BarHeight specifies the height of each horizontal bar.
	BarHeight int
	// ValueFormatter defines how float values should be rendered to strings, notably for numeric axis labels.
	ValueFormatter ValueFormatter
}

func NewHorizontalBarChartOptionWithData added in v0.4.0

func NewHorizontalBarChartOptionWithData(data [][]float64) HorizontalBarChartOption

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

type LegendOption

type LegendOption struct {
	// Show specifies if the legend should be rendered, set this to *false (through False()) to hide the legend.
	Show *bool
	// Theme specifies the colors used for the legend.
	Theme ColorPalette
	// Data provides text for the legend.
	Data []string
	// FontStyle specifies the font, size, and style for rendering the legend.
	FontStyle FontStyle
	// Padding specifies space padding around the legend.
	Padding Box
	// Offset allows you to specify the position of the legend component relative to the left and top side.
	Offset OffsetStr
	// Align is the legend marker and text alignment, it can be 'left', 'right' or 'center', default is 'left'.
	Align string
	// Vertical can be set to *true to set the legend orientation to be vertical.
	Vertical *bool
	// Icon to show next to the labels.	Can be 'rect' or 'dot'.
	Icon string
	// OverlayChart can be set to *true to render the legend over the chart. Ignored if Vertical is set to true (always overlapped).
	OverlayChart *bool
}

func (*LegendOption) IsEmpty

func (opt *LegendOption) IsEmpty() bool

IsEmpty checks legend is empty

type LineChartOption

type LineChartOption struct {
	// Theme specifies the colors used for the line chart.
	Theme ColorPalette
	// Padding specifies the padding of line chart.
	Padding Box
	// Font is the font used to render the chart.
	Font *truetype.Font
	// SeriesList provides the data series.
	SeriesList SeriesList
	// XAxis are options for the x-axis.
	XAxis XAxisOption
	// YAxis are options for the y-axis (at most two).
	YAxis []YAxisOption
	// Title are options for rendering the title.
	Title TitleOption
	// Legend are options for the data legend.
	Legend LegendOption
	// SymbolShow set this to *false or *true (using False() or True()) to force if the symbols should be shown or hidden.
	SymbolShow *bool
	// LineStrokeWidth is the width of the rendered line.
	LineStrokeWidth float64
	// StrokeSmoothingTension should be between 0 and 1. At 0 perfectly straight lines will be used with 1 providing
	// smoother lines. Because the tension smooths out the line, the line will no longer hit the data points exactly.
	// The more variable the points, and the higher the tension, the more the line will be moved from the points.
	StrokeSmoothingTension float64
	// FillArea set this to true to fill the area below the line.
	FillArea bool
	// FillOpacity is the opacity (alpha) of the area fill.
	FillOpacity uint8
	// ValueFormatter defines how float values should be rendered to strings, notably for numeric axis labels.
	ValueFormatter ValueFormatter
	// contains filtered or unexported fields
}

func NewLineChartOptionWithData added in v0.4.0

func NewLineChartOptionWithData(data [][]float64) LineChartOption

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

type LineSeriesOption added in v0.4.0

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

LineSeriesOption provides series customization for NewSeriesListLine.

type OffsetInt added in v0.3.0

type OffsetInt struct {
	// Left 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

func (OffsetInt) WithTop added in v0.3.0

func (o OffsetInt) WithTop(val int) OffsetInt

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

func (OffsetStr) WithLeftI added in v0.3.0

func (o OffsetStr) WithLeftI(val int) OffsetStr

func (OffsetStr) WithTop added in v0.3.0

func (o OffsetStr) WithTop(val string) OffsetStr

func (OffsetStr) WithTopI added in v0.3.0

func (o OffsetStr) WithTopI(val int) OffsetStr

type OptionFunc

type OptionFunc func(opt *ChartOption)

OptionFunc option function

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

func FontOptionFunc(font *truetype.Font) OptionFunc

FontOptionFunc set font of chart.

func LegendLabelsOptionFunc

func LegendLabelsOptionFunc(labels []string) OptionFunc

LegendLabelsOptionFunc set legend labels of chart

func LegendOptionFunc

func LegendOptionFunc(legend LegendOption) OptionFunc

LegendOptionFunc set legend of chart

func MarkLineOptionFunc

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

MarkLineOptionFunc set mark line for series of chart

func MarkPointOptionFunc

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

MarkPointOptionFunc set mark point for series of chart

func PNGOutputOptionFunc added in v0.4.0

func PNGOutputOptionFunc() OptionFunc

PNGOutputOptionFunc set png type of chart's output.

func PaddingOptionFunc

func PaddingOptionFunc(padding Box) OptionFunc

PaddingOptionFunc set padding of chart

func RadarIndicatorOptionFunc

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

RadarIndicatorOptionFunc set radar indicator of chart

func SVGOutputOptionFunc added in v0.4.0

func SVGOutputOptionFunc() OptionFunc

SVGOutputOptionFunc set svg type of chart's output.

func SeriesShowLabel added in v0.4.0

func SeriesShowLabel(show bool) OptionFunc

SeriesShowLabel set the series show label state for all series.

func ThemeNameOptionFunc

func ThemeNameOptionFunc(theme string) OptionFunc

ThemeNameOptionFunc set them of chart by name.

func ThemeOptionFunc

func ThemeOptionFunc(theme ColorPalette) OptionFunc

ThemeOptionFunc set them of chart

func TitleOptionFunc

func TitleOptionFunc(title TitleOption) OptionFunc

TitleOptionFunc set title of chart

func TitleTextOptionFunc

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

TitleTextOptionFunc set title text of chart

func XAxisDataOptionFunc

func XAxisDataOptionFunc(data []string) OptionFunc

XAxisDataOptionFunc set x-axis data of chart

func XAxisOptionFunc

func XAxisOptionFunc(xAxisOption XAxisOption) OptionFunc

XAxisOptionFunc set x-axis of chart

func YAxisDataOptionFunc

func YAxisDataOptionFunc(data []string) OptionFunc

YAxisDataOptionFunc set y-axis data of chart

func YAxisOptionFunc

func YAxisOptionFunc(yAxisOption ...YAxisOption) OptionFunc

YAxisOptionFunc set 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 bar chart render

func FunnelRender

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

FunnelRender funnel chart render

func HorizontalBarRender

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

HorizontalBarRender horizontal bar chart render

func LineRender

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

LineRender line chart render

func NewPainter

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

NewPainter creates a painter which can be used to render charts to (using for example newLineChart).

func PieRender

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

PieRender pie chart render

func RadarRender

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

RadarRender radar chart render

func Render

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

func TableOptionRenderDirect added in v0.4.0

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

TableOptionRenderDirect table render with the provided options directly to an image. Table options are different from other charts as they include the state for initializing the Painter, where other charts accept the Painter. If you want to write 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 simple header and data values provided.

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) Child

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

Child returns a painter with the passed-in options applied to it. Useful when you want to render relative to only 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) Dots

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

Dots prints filled circles for the given points.

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) 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) 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) 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 will be skipped, resulting in a gap. Single or isolated points will result in just a dot being drawn at the point.

func (*Painter) MarkLine

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

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

func (*Painter) MeasureText

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

MeasureText will provide 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) SetBackground

func (p *Painter) SetBackground(width, height int, color Color)

SetBackground fills the entire painter area with the given color.

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 the tension smooths out the line, the line will no longer hit the provided points exactly. The more variable the points, and the higher the tension, the more the line will be.

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 position specified, using the given font style. Specifying radians will rotate the text.

func (*Painter) TextFit

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

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

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 box for the Painter to draw within.

func PainterFontOption

func PainterFontOption(font *truetype.Font) PainterOptionFunc

PainterFontOption sets the default font face for the Painter. This font is used if the FontStyle specified in chart configs does not specify another face.

func PainterPaddingOption

func PainterPaddingOption(padding Box) PainterOptionFunc

PainterPaddingOption sets the padding of the draw painter.

func PainterThemeOption

func PainterThemeOption(theme ColorPalette) PainterOptionFunc

PainterThemeOption sets a color palette theme default for the Painter. This theme is used if the specific chart options don't have a theme set.

type PainterOptions

type PainterOptions struct {
	// OutputFormat specifies the output type, "svg" or "png", default is "png".
	OutputFormat string
	// Width is the width of the draw painter.
	Width int
	// Height is the height of the draw painter.
	Height int
	// Font is the default font used for rendering text.
	Font *truetype.Font
	// Theme is the default theme to be used if the chart does not specify a theme.
	Theme ColorPalette
}

PainterOptions contains parameters for creating a new Painter.

type PieChartOption

type PieChartOption struct {
	// Theme specifies the colors used for the pie chart.
	Theme ColorPalette
	// Padding specifies the padding of pie chart.
	Padding Box
	// Font is the font used to render the chart.
	Font *truetype.Font
	// SeriesList provides the data series.
	SeriesList SeriesList
	// Title are options for rendering the title.
	Title TitleOption
	// Legend are options for the data legend.
	Legend LegendOption
	// contains filtered or unexported fields
}

func NewPieChartOptionWithData added in v0.4.0

func NewPieChartOptionWithData(data []float64) PieChartOption

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

type PieSeriesOption

type PieSeriesOption struct {
	Radius string
	Label  SeriesLabel
	Names  []string
}

PieSeriesOption provides series customization for NewSeriesListPie.

type Point

type Point = chartdraw.Point

type RadarChartOption

type RadarChartOption struct {
	// Theme specifies the colors used for the pie chart.
	Theme ColorPalette
	// Padding specifies the padding of pie chart.
	Padding Box
	// Font is the font used to render the chart.
	Font *truetype.Font
	// SeriesList provides the data series.
	SeriesList SeriesList
	// Title are options for rendering the title.
	Title TitleOption
	// Legend are options for the data legend.
	Legend LegendOption
	// RadarIndicators provides the radar indicator list.
	RadarIndicators []RadarIndicator
	// contains filtered or unexported fields
}

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 for the provided data slice.

type RadarIndicator

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

func NewRadarIndicators

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

NewRadarIndicators returns a radar indicator list

type RadarSeriesOption added in v0.4.0

type RadarSeriesOption struct {
	Label SeriesLabel
	Names []string
}

RadarSeriesOption provides series customization for NewSeriesListRadar.

type Series

type Series struct {

	// Type is the type of series, it can be "line", "bar" or "pie". Default value is "line".
	Type string
	// Data provides the series data list.
	Data []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
	// Radius for Pie chart, e.g.: 40%, default is "40%"
	Radius string
	// MarkPoint provides a series for mark points.
	MarkPoint SeriesMarkPoint
	// MarkLine provides a series for mark lines.
	MarkLine SeriesMarkLine
	// contains filtered or unexported fields
}

Series references a population of data.

func (*Series) Summary

func (s *Series) Summary() seriesSummary

Summary returns numeric summary of series values (population statistics).

type SeriesLabel

type SeriesLabel struct {
	// Data label formatter, which supports string template.
	// {b}: the name of a data item.
	// {c}: the value of a data item.
	// {d}: the percent of a data item(pie chart).
	Formatter string
	// FontStyle specifies the font and style for the label.
	FontStyle FontStyle
	// Show flag for label, if unset the behavior will be defaulted based on the chart.
	Show *bool
	// Distance to the host graphic element.
	Distance int // TODO - do we want to replace with just Offset?
	// Position defines the label position.
	Position string
	// Offset specifies an offset from the position.
	Offset OffsetInt
}

type SeriesList

type SeriesList []Series

SeriesList is a list of series to be rendered on the chart, typically constructed using NewSeriesListLine, NewSeriesListBar, NewSeriesListHorizontalBar, NewSeriesListPie, NewSeriesListRadar, or NewSeriesListFunnel. These Series can be appended to each other if multiple chart types should be rendered to the same axis.

func NewSeriesListBar added in v0.4.0

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

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 NewSeriesListFunnel added in v0.4.0

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

NewSeriesListFunnel builds a series list for funnel charts.

func NewSeriesListHorizontalBar added in v0.4.0

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

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 NewSeriesListLine added in v0.4.0

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

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 NewSeriesListPie added in v0.4.0

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

NewSeriesListPie builds a SeriesList for a pie chart.

func NewSeriesListRadar added in v0.4.0

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

NewSeriesListRadar builds a SeriesList for a Radar chart.

func (SeriesList) Filter

func (sl SeriesList) Filter(chartType string) SeriesList

func (SeriesList) GetMinMax

func (sl SeriesList) GetMinMax(yaxisIndex int) (float64, float64)

GetMinMax get max and min value of series list for a given y-axis index (either 0 or 1).

func (SeriesList) Names

func (sl SeriesList) Names() []string

Names returns the names of series list.

type SeriesMarkData

type SeriesMarkData struct {
	// Type is the mark data type, it can be "max", "min", "average". "average" is only for mark line.
	Type string
}

type SeriesMarkLine

type SeriesMarkLine struct {
	// Data is the mark data for the series mark line.
	Data []SeriesMarkData
}

func NewMarkLine

func NewMarkLine(markLineTypes ...string) SeriesMarkLine

NewMarkLine returns a series mark line

type SeriesMarkPoint

type SeriesMarkPoint struct {
	// SymbolSize is the width of symbol, default value is 30.
	SymbolSize int
	// Data is the mark data for the series mark point.
	Data []SeriesMarkData
}

func NewMarkPoint

func NewMarkPoint(markPointTypes ...string) SeriesMarkPoint

NewMarkPoint returns a series mark point

type TableCell

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

type TableChartOption

type TableChartOption struct {
	// OutputFormat specifies the output type, "svg" or "png".
	OutputFormat string
	// Theme specifies the colors used for the table.
	Theme ColorPalette
	// Padding specifies the padding of 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 provide the span for each column on the table.
	Spans []int
	// TextAligns specifies the text alignment for each cell on the table.
	TextAligns []string
	// FontStyle contains the configuration for the table text font.
	FontStyle FontStyle
	// HeaderBackgroundColor provides a background color of header row.
	HeaderBackgroundColor Color
	// HeaderFontColor specifies a text color for the header text.
	HeaderFontColor Color
	// RowBackgroundColors specifies an array of colors for each row.
	RowBackgroundColors []Color
	// BackgroundColor specifies a general background color.
	BackgroundColor Color
	// CellModifier is an optional function to modify the style or content of a specific TableCell before they are rendered.
	CellModifier func(TableCell) TableCell
}

type ThemeOption

type ThemeOption struct {
	IsDarkMode         bool
	AxisStrokeColor    Color
	AxisSplitLineColor Color
	BackgroundColor    Color
	TextColor          Color
	SeriesColors       []Color
}

type TitleOption

type TitleOption struct {
	// Show specifies if the title should be rendered, set this to *false (through False()) to hide the title.
	Show *bool
	// Theme specifies the colors used for the title.
	Theme ColorPalette
	// Text specifies the title text, supporting \n for new lines.
	Text string
	// Subtext to the title, supporting \n for new lines.
	Subtext string
	// Offset allows you to specify the position of the title component relative to the left and top side.
	Offset OffsetStr
	// FontStyle specifies the font, size, and style for rendering the title.
	FontStyle FontStyle
	// SubtextFontStyle specifies the font, size, and style for rendering the subtext.
	SubtextFontStyle FontStyle
}

type ValueFormatter

type ValueFormatter func(float64) string

ValueFormatter defines a function that can be used to format numeric values.

type XAxisOption

type XAxisOption struct {
	// Show specifies if the x-axis should be rendered, set this to *false (through False()) to hide the axis.
	Show *bool
	// Theme specifies the colors used for the x-axis.
	Theme ColorPalette
	// Data provides labels for the x-axis.
	Data []string
	// DataStartIndex specifies what index the Data values should start from.
	DataStartIndex int
	// Position describes the position of x-axis, it can be 'top' or 'bottom'.
	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.False() or charts.True()) to enforce a spacing.
	BoundaryGap *bool
	// FontStyle specifies the font configuration for each label.
	FontStyle FontStyle
	// TextRotation are the radians for rotating the label.
	TextRotation float64
	// LabelOffset is the offset of each label.
	LabelOffset OffsetInt
	// ValueFormatter defines how float values should be rendered to strings, notably for numeric axis labels.
	ValueFormatter ValueFormatter
	// Unit is a suggestion for how large the axis step is, this is a recommendation only. Larger numbers result in fewer labels.
	Unit float64
	// LabelCount is the number of labels to show on the axis. Specify a smaller number to reduce writing 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
	// contains filtered or unexported fields
}

type YAxisOption

type YAxisOption struct {
	// Show specifies if the y-axis should be rendered, set this to *false (through False()) to hide the axis.
	Show *bool
	// Theme specifies the colors used for the x-axis.
	Theme ColorPalette
	// Color for y-axis.
	AxisColor Color
	// Min, if set this will force the minimum value of y-axis.
	Min *float64
	// Max, if set this will force the maximum value of y-axis.
	Max *float64
	// RangeValuePaddingScale suggest a scale of padding added to the max and min values.
	RangeValuePaddingScale *float64
	// Data provides labels for the y-axis.
	Data []string
	// Position describes the position of y-axis, it can be 'left' or 'right'.
	Position string
	// FontStyle specifies the font configuration for each label.
	FontStyle FontStyle
	// Formatter for replacing y-axis text values.
	Formatter string
	// Unit is a suggestion for how large the axis step is, this is a recommendation only. Larger numbers result in fewer labels.
	Unit float64
	// LabelCount is the number of labels to show on the axis. Specify a smaller number to reduce writing 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
	// LabelSkipCount specifies a number of lines between labels where there will be no label and instead just a horizontal line.
	LabelSkipCount int

	// SplitLineShow for showing axis split line, set this to true to show the horizontal axis split lines.
	SplitLineShow *bool
	// SpineLineShow can be set to enforce if the vertical spine on the axis should be shown or not.
	// By default, not shown unless a category axis.
	SpineLineShow *bool
	// ValueFormatter defines how float values should be rendered to strings, notably for numeric axis labels.
	ValueFormatter ValueFormatter
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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