chart

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package chart is the chart library of the Tango self-drawn UI: line, area, column / bar, pie / donut, scatter / bubble, radar, gauge, funnel, heatmap, dual axes, liquid and tiny (sparkline) charts, drawn with the ui/paint display list and styled after Ant Design Charts (G2) for the Ant flavor and ECharts for Element Plus.

Charts are built per frame like every other widget, with a chain that ends in Show:

chart.Line(c, rows).X("month").Y("value").Series("city").Smooth().Show()
chart.Column(c, rows).X("month").Y("sales").Series("shop").Stack().Show()
chart.Pie(c, rows).Angle("value").Color("type").Inner(0.64).Show()
chart.TinyArea(c, []float64{3, 5, 2, 8, 6}).Show()

Data is a []chart.Row (map[string]any); RowsOf converts a typed slice. Field values may be numbers of any Go numeric type, strings (categories) or time.Time. Legends toggle series, tooltips follow the pointer with a crosshair, values animate on entry and when the data changes, and long lines are downsampled with LTTB to the plot width.

In right-to-left scopes the plot keeps its left-to-right geometry (time and value axes read left to right in data visualisation), while the chrome follows the scope: legend items flow from the inline start and LegendLeft / LegendRight mean start / end, tooltips open on the inline end side with right-to-left rows, and category, time and other label text is shaped right to left (numbers keep their own direction). Mirror opts into a mirrored plot: the x axis runs right to left with the value axis on the right, and polar charts sweep counter-clockwise.

The building blocks are exported for custom charts: scales (Linear, Log, TimeScale, Band, Point), tick generation (NiceTicks, TimeTicks), number formatting (FormatNumber, FormatCompact), stacking (Stack), downsampling (LTTB), coordinates (Cartesian, Polar) and the theme-aware Style with its palette registry (RegisterStyle).

Experimental: this package's API may change in any 0.x release (see docs/release.md, "API 稳定性").

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DataTable

func DataTable(c *ui.Context, rows []Row, fields ...string) *ui.TableW

DataTable builds a ui.Table of rows with one column per field (titled by the field name): the accessible alternative of a chart, for apps that offer a "view as table" toggle next to it.

if showTable {
	chart.DataTable(c, rows, "month", "city", "temp").Show()
} else {
	chart.Line(c, rows).X("month").Y("temp").Series("city").Show()
}

func FormatCompact

func FormatCompact(v float64, locale string) string

FormatCompact abbreviates large values: 万 / 亿 for Chinese locales ("zh-CN"), K / M / B otherwise. Values below the first unit keep thousands separators.

func FormatNumber

func FormatNumber(v float64, decimals int) string

FormatNumber formats v with thousands separators and the given number of decimals (negative: shortest exact representation).

func LTTB

func LTTB(xs, ys []float64, threshold int) []int

LTTB downsamples the series (xs[i], ys[i]) to at most threshold points with the Largest-Triangle-Three-Buckets algorithm (Steinarsson, 2013, "Downsampling Time Series for Visual Representation"). It returns the indices of the kept points in ascending order; the first and last points are always kept. NaN y values are skipped. With threshold < 3 or fewer points than threshold, every valid index is returned.

func NiceDomain

func NiceDomain(lo, hi float64, count int) (nlo, nhi, step float64)

NiceDomain extends [lo, hi] outward to multiples of a nice step with about count ticks. A zero span is widened around the value (0 becomes [0, 1]); NaN or infinite input yields [0, 1].

func NiceStep

func NiceStep(span float64, count int) float64

NiceStep returns a round tick step (1, 2 or 5 × 10^k) that divides span into about count intervals.

func NiceTicks

func NiceTicks(lo, hi float64, count int) []float64

NiceTicks returns the nice domain and its ticks for data in [lo, hi].

func Num

func Num(v any) (float64, bool)

Num converts a field value to float64. Strings are not parsed: a string is a category, not a number.

func RegisterStyle

func RegisterStyle(match func(*theme.Theme) bool, fn StyleFunc)

RegisterStyle installs a chart style for themes accepted by match; later registrations take precedence. Built-in styles: Ant (G2 classic) for theme.Ant and ECharts for theme.Element, each with a dark variant.

chart.RegisterStyle(func(t *theme.Theme) bool { return t.Name == "shadcn" },
	func(t *theme.Theme) *chart.Style {
		s := chart.AntStyle(t)
		s.Colors = shadcnPalette
		return s
	})

func Stack

func Stack(vals [][]float64, hidden []bool, percent bool) (lo, hi [][]float64)

Stack stacks series values per x position. vals[s][i] is the value of series s at x i (NaN = missing, treated as 0); hidden series contribute nothing. Positive values stack upward from 0 and negative values downward, so mixed signs never overlap. With percent each column is normalised so the absolute values sum to 1 (positives to the share above 0, negatives below). It returns the lower and upper bound of every segment.

func Str

func Str(v any) string

Str converts a field value to its category label.

func TimeOf

func TimeOf(v any) (time.Time, bool)

TimeOf converts a field value to a time.

Types

type Band

type Band struct {
	N            int
	R0, R1       float64
	PaddingInner float64 // fraction of the step left empty between bands
	PaddingOuter float64 // fraction of the step before the first / after the last band
}

Band divides the range into equal bands, one per category (bars).

func (Band) Bandwidth

func (s Band) Bandwidth() float64

Bandwidth returns the width of one band.

func (Band) Center

func (s Band) Center(i int) float64

Center returns the middle of band i.

func (Band) Index

func (s Band) Index(p float64) int

Index returns the band whose step contains p (-1 outside).

func (Band) Map

func (s Band) Map(i int) float64

Map returns the start of band i.

func (Band) Step

func (s Band) Step() float64

Step returns the distance between band starts.

type Cartesian

type Cartesian struct {
	Plot       geom.Rect
	Transposed bool
	Mirror     bool
}

Cartesian maps normalised coordinates (0..1, y up) into a plot rect. Transposed swaps the axes: x runs top to bottom and y left to right (horizontal bars). Mirror reverses the horizontal pixel axis: it runs right to left (x for columns, y for horizontal bars).

func (Cartesian) At

func (c Cartesian) At(nx, ny float64) geom.Point

At returns the pixel position of normalised (nx, ny).

func (Cartesian) HX

func (c Cartesian) HX(t float64) float32

HX returns the pixel x of normalised position t on the horizontal pixel axis (x, or y when transposed).

func (Cartesian) Norm

func (c Cartesian) Norm(pt geom.Point) (nx, ny float64)

Norm inverts At.

func (Cartesian) Rect

func (c Cartesian) Rect(x0, x1, y0, y1 float64) geom.Rect

Rect returns the pixel rect spanning normalised x0..x1 and y0..y1.

type Color

type Color = theme.Color

Color is a theme color (ramps, overrides).

type ColumnW

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

ColumnW builds a column (vertical) or bar (horizontal) chart.

func Bar

func Bar(c *ui.Context, data []Row) *ColumnW

Bar starts a horizontal bar chart: X is the category field (listed top to bottom), Y the value.

func Column

func Column(c *ui.Context, data []Row) *ColumnW

Column starts a vertical bar chart. With Series the bars are grouped side by side; Stack and Percent stack them instead.

chart.Column(c, rows).X("month").Y("sales").Series("shop").Stack().Show()

func (*ColumnW) A11yLabel

func (b *ColumnW) A11yLabel(s string) *T

A11yLabel sets the accessible name of the chart (default: its title or the localized chart kind, e.g. "折线图").

func (*ColumnW) Animate

func (b *ColumnW) Animate(on bool) *T

Animate enables (default) or disables entry and update transitions.

func (*ColumnW) Colors

func (b *ColumnW) Colors(cs ...theme.Color) *T

Colors overrides the palette.

func (*ColumnW) Format

func (b *ColumnW) Format(f Formatter) *T

Format sets the value formatter used by the value axis, tooltip and labels (default: thousands separators).

func (*ColumnW) Height

func (b *ColumnW) Height(h float32) *T

Height sets the chart height in logical pixels (the width follows the parent).

func (*ColumnW) Key

func (b *ColumnW) Key(k any) *T

Key gives the chart a stable identity (legend and animation state) when charts are added or removed around it.

func (*ColumnW) Label

func (b *ColumnW) Label() *T

Label shows data labels on the marks.

func (*ColumnW) Layout

func (b *ColumnW) Layout(o ...layout.Option) *T

Layout applies layout options to the chart box (Grow, Margin ...).

func (*ColumnW) Legend

func (b *ColumnW) Legend(p LegendPos) *T

Legend places (or with LegendNone hides) the legend.

func (*ColumnW) Loading

func (b *ColumnW) Loading(on bool) *T

Loading shows a spinner over the chart (or in place of it without data).

func (*ColumnW) MaxWidth

func (w *ColumnW) MaxWidth(px float32) *ColumnW

MaxWidth caps the bar thickness.

func (*ColumnW) Mirror

func (b *ColumnW) Mirror() *T

Mirror draws the plot right to left: the x axis runs from the right, the value axis sits on the right, bars, lines, areas and points are mirrored (so categories read in reverse order), and pie, donut, radar and gauge start at the mirrored angle and sweep counter-clockwise. Labels stay readable; only their positions move. Without it the plot is drawn left to right even in RTL scopes, while the legend, tooltip and labels follow the scope direction.

func (*ColumnW) NoTooltip

func (b *ColumnW) NoTooltip() *T

NoTooltip disables the hover tooltip and crosshair.

func (*ColumnW) NoZero

func (o *ColumnW) NoZero() *T

NoZero lets the value axis start near the data instead of at zero.

func (*ColumnW) Padding

func (w *ColumnW) Padding(p float64) *ColumnW

Padding sets the empty fraction between bands (0..1).

func (*ColumnW) Percent

func (w *ColumnW) Percent() *ColumnW

Percent stacks the series normalised to 100%.

func (*ColumnW) Radius

func (w *ColumnW) Radius(r float32) *ColumnW

Radius rounds the bar ends.

func (*ColumnW) Series

func (o *ColumnW) Series(field string) *T

Series sets the field that splits rows into series (legend, colors).

func (*ColumnW) Show

func (w *ColumnW) Show() View

Show builds the chart.

func (*ColumnW) Stack

func (w *ColumnW) Stack() *ColumnW

Stack stacks the series.

func (*ColumnW) Style

func (b *ColumnW) Style(fn func(*Style)) *T

Style tweaks the resolved chart style for this chart only.

func (*ColumnW) X

func (o *ColumnW) X(field string) *T

X sets the x (category / time / number) field.

func (*ColumnW) Y

func (o *ColumnW) Y(field string) *T

Y sets the value field.

func (*ColumnW) YMax

func (o *ColumnW) YMax(v float64) *T

YMax fixes the upper end of the value axis.

func (*ColumnW) YMin

func (o *ColumnW) YMin(v float64) *T

YMin fixes the lower end of the value axis.

type DualW

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

DualW builds a dual-axes chart: columns on the left axis, lines on the right axis, over a shared category x.

func DualAxes

func DualAxes(c *ui.Context, data []Row) *DualW

DualAxes starts a column + line chart.

chart.DualAxes(c, rows).X("month").Column("sales").Line("rate").Show()

func (*DualW) A11yLabel

func (b *DualW) A11yLabel(s string) *T

A11yLabel sets the accessible name of the chart (default: its title or the localized chart kind, e.g. "折线图").

func (*DualW) Alias

func (w *DualW) Alias(field, name string) *DualW

Alias sets the legend / tooltip name of a field.

func (*DualW) Animate

func (b *DualW) Animate(on bool) *T

Animate enables (default) or disables entry and update transitions.

func (*DualW) Colors

func (b *DualW) Colors(cs ...theme.Color) *T

Colors overrides the palette.

func (*DualW) Column

func (w *DualW) Column(fields ...string) *DualW

Column adds fields drawn as grouped columns on the left axis.

func (*DualW) Format

func (b *DualW) Format(f Formatter) *T

Format sets the value formatter used by the value axis, tooltip and labels (default: thousands separators).

func (*DualW) Height

func (b *DualW) Height(h float32) *T

Height sets the chart height in logical pixels (the width follows the parent).

func (*DualW) Key

func (b *DualW) Key(k any) *T

Key gives the chart a stable identity (legend and animation state) when charts are added or removed around it.

func (*DualW) Label

func (b *DualW) Label() *T

Label shows data labels on the marks.

func (*DualW) Layout

func (b *DualW) Layout(o ...layout.Option) *T

Layout applies layout options to the chart box (Grow, Margin ...).

func (*DualW) Legend

func (b *DualW) Legend(p LegendPos) *T

Legend places (or with LegendNone hides) the legend.

func (*DualW) Line

func (w *DualW) Line(fields ...string) *DualW

Line adds fields drawn as lines on the right axis.

func (*DualW) LineFormat

func (w *DualW) LineFormat(f Formatter) *DualW

LineFormat formats the right axis and line values.

func (*DualW) Loading

func (b *DualW) Loading(on bool) *T

Loading shows a spinner over the chart (or in place of it without data).

func (*DualW) Mirror

func (b *DualW) Mirror() *T

Mirror draws the plot right to left: the x axis runs from the right, the value axis sits on the right, bars, lines, areas and points are mirrored (so categories read in reverse order), and pie, donut, radar and gauge start at the mirrored angle and sweep counter-clockwise. Labels stay readable; only their positions move. Without it the plot is drawn left to right even in RTL scopes, while the legend, tooltip and labels follow the scope direction.

func (*DualW) NoTooltip

func (b *DualW) NoTooltip() *T

NoTooltip disables the hover tooltip and crosshair.

func (*DualW) Show

func (w *DualW) Show() View

Show builds the chart.

func (*DualW) Smooth

func (w *DualW) Smooth() *DualW

Smooth draws the lines as monotone curves.

func (*DualW) Style

func (b *DualW) Style(fn func(*Style)) *T

Style tweaks the resolved chart style for this chart only.

func (*DualW) X

func (w *DualW) X(field string) *DualW

X sets the category field.

type Formatter

type Formatter func(v float64) string

Formatter turns a value into a label.

func Compact

func Compact(locale string) Formatter

Compact returns FormatCompact bound to a locale code (c.Locale().Code).

func Percent

func Percent(decimals int) Formatter

Percent formats a ratio (0.256 → "25.6%").

func Thousands

func Thousands(decimals int) Formatter

Thousands returns a formatter with thousands separators.

func Unit

func Unit(unit string, decimals int) Formatter

Unit appends a unit suffix to a thousands-separated value.

type FunnelW

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

FunnelW builds a funnel chart.

func Funnel

func Funnel(c *ui.Context, data []Row) *FunnelW

Funnel starts a funnel: X is the stage field, Y the value; stages keep the row order (largest first).

chart.Funnel(c, rows).X("stage").Y("count").Show()

func (*FunnelW) A11yLabel

func (b *FunnelW) A11yLabel(s string) *T

A11yLabel sets the accessible name of the chart (default: its title or the localized chart kind, e.g. "折线图").

func (*FunnelW) Animate

func (b *FunnelW) Animate(on bool) *T

Animate enables (default) or disables entry and update transitions.

func (*FunnelW) Colors

func (b *FunnelW) Colors(cs ...theme.Color) *T

Colors overrides the palette.

func (*FunnelW) Format

func (b *FunnelW) Format(f Formatter) *T

Format sets the value formatter used by the value axis, tooltip and labels (default: thousands separators).

func (*FunnelW) Height

func (b *FunnelW) Height(h float32) *T

Height sets the chart height in logical pixels (the width follows the parent).

func (*FunnelW) Key

func (b *FunnelW) Key(k any) *T

Key gives the chart a stable identity (legend and animation state) when charts are added or removed around it.

func (*FunnelW) Label

func (b *FunnelW) Label() *T

Label shows data labels on the marks.

func (*FunnelW) Layout

func (b *FunnelW) Layout(o ...layout.Option) *T

Layout applies layout options to the chart box (Grow, Margin ...).

func (*FunnelW) Legend

func (b *FunnelW) Legend(p LegendPos) *T

Legend places (or with LegendNone hides) the legend.

func (*FunnelW) Loading

func (b *FunnelW) Loading(on bool) *T

Loading shows a spinner over the chart (or in place of it without data).

func (*FunnelW) Mirror

func (b *FunnelW) Mirror() *T

Mirror draws the plot right to left: the x axis runs from the right, the value axis sits on the right, bars, lines, areas and points are mirrored (so categories read in reverse order), and pie, donut, radar and gauge start at the mirrored angle and sweep counter-clockwise. Labels stay readable; only their positions move. Without it the plot is drawn left to right even in RTL scopes, while the legend, tooltip and labels follow the scope direction.

func (*FunnelW) NoConversion

func (w *FunnelW) NoConversion() *FunnelW

NoConversion hides the stage-to-stage conversion rates.

func (*FunnelW) NoTooltip

func (b *FunnelW) NoTooltip() *T

NoTooltip disables the hover tooltip and crosshair.

func (*FunnelW) Show

func (w *FunnelW) Show() View

Show builds the chart.

func (*FunnelW) Style

func (b *FunnelW) Style(fn func(*Style)) *T

Style tweaks the resolved chart style for this chart only.

func (*FunnelW) X

func (w *FunnelW) X(field string) *FunnelW

X sets the stage field.

func (*FunnelW) Y

func (w *FunnelW) Y(field string) *FunnelW

Y sets the value field.

type GaugeW

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

GaugeW builds a gauge (dial) chart.

func Gauge

func Gauge(c *ui.Context, value float64) *GaugeW

Gauge starts a gauge showing value on the range 0..1 (see Range).

chart.Gauge(c, 0.72).Title("完成率").Show()

func (*GaugeW) A11yLabel

func (b *GaugeW) A11yLabel(s string) *T

A11yLabel sets the accessible name of the chart (default: its title or the localized chart kind, e.g. "折线图").

func (*GaugeW) Animate

func (b *GaugeW) Animate(on bool) *T

Animate enables (default) or disables entry and update transitions.

func (*GaugeW) Bands

func (w *GaugeW) Bands(stops []float64, colors ...theme.Color) *GaugeW

Bands colors the track by thresholds (upper bounds in scale units, sorted) instead of a single progress arc.

func (*GaugeW) Colors

func (b *GaugeW) Colors(cs ...theme.Color) *T

Colors overrides the palette.

func (*GaugeW) Format

func (b *GaugeW) Format(f Formatter) *T

Format sets the value formatter used by the value axis, tooltip and labels (default: thousands separators).

func (*GaugeW) Height

func (b *GaugeW) Height(h float32) *T

Height sets the chart height in logical pixels (the width follows the parent).

func (*GaugeW) Key

func (b *GaugeW) Key(k any) *T

Key gives the chart a stable identity (legend and animation state) when charts are added or removed around it.

func (*GaugeW) Label

func (b *GaugeW) Label() *T

Label shows data labels on the marks.

func (*GaugeW) Layout

func (b *GaugeW) Layout(o ...layout.Option) *T

Layout applies layout options to the chart box (Grow, Margin ...).

func (*GaugeW) Legend

func (b *GaugeW) Legend(p LegendPos) *T

Legend places (or with LegendNone hides) the legend.

func (*GaugeW) Loading

func (b *GaugeW) Loading(on bool) *T

Loading shows a spinner over the chart (or in place of it without data).

func (*GaugeW) Mirror

func (b *GaugeW) Mirror() *T

Mirror draws the plot right to left: the x axis runs from the right, the value axis sits on the right, bars, lines, areas and points are mirrored (so categories read in reverse order), and pie, donut, radar and gauge start at the mirrored angle and sweep counter-clockwise. Labels stay readable; only their positions move. Without it the plot is drawn left to right even in RTL scopes, while the legend, tooltip and labels follow the scope direction.

func (*GaugeW) NoTooltip

func (b *GaugeW) NoTooltip() *T

NoTooltip disables the hover tooltip and crosshair.

func (*GaugeW) Range

func (w *GaugeW) Range(lo, hi float64) *GaugeW

Range sets the scale bounds (default 0..1, shown as percentages).

func (*GaugeW) Show

func (w *GaugeW) Show() View

Show builds the chart.

func (*GaugeW) Style

func (b *GaugeW) Style(fn func(*Style)) *T

Style tweaks the resolved chart style for this chart only.

func (*GaugeW) Title

func (w *GaugeW) Title(s string) *GaugeW

Title sets the caption under the value.

type HeatmapW

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

HeatmapW builds a heatmap over two category fields.

func Heatmap

func Heatmap(c *ui.Context, data []Row) *HeatmapW

Heatmap starts a heatmap: X and Y are category fields, Value the numeric field mapped onto the sequential palette.

chart.Heatmap(c, rows).X("hour").Y("weekday").Value("count").Show()

func (*HeatmapW) A11yLabel

func (b *HeatmapW) A11yLabel(s string) *T

A11yLabel sets the accessible name of the chart (default: its title or the localized chart kind, e.g. "折线图").

func (*HeatmapW) Animate

func (b *HeatmapW) Animate(on bool) *T

Animate enables (default) or disables entry and update transitions.

func (*HeatmapW) Colors

func (b *HeatmapW) Colors(cs ...theme.Color) *T

Colors overrides the palette.

func (*HeatmapW) Format

func (b *HeatmapW) Format(f Formatter) *T

Format sets the value formatter used by the value axis, tooltip and labels (default: thousands separators).

func (*HeatmapW) Height

func (b *HeatmapW) Height(h float32) *T

Height sets the chart height in logical pixels (the width follows the parent).

func (*HeatmapW) Key

func (b *HeatmapW) Key(k any) *T

Key gives the chart a stable identity (legend and animation state) when charts are added or removed around it.

func (*HeatmapW) Label

func (b *HeatmapW) Label() *T

Label shows data labels on the marks.

func (*HeatmapW) Layout

func (b *HeatmapW) Layout(o ...layout.Option) *T

Layout applies layout options to the chart box (Grow, Margin ...).

func (*HeatmapW) Legend

func (b *HeatmapW) Legend(p LegendPos) *T

Legend places (or with LegendNone hides) the legend.

func (*HeatmapW) Loading

func (b *HeatmapW) Loading(on bool) *T

Loading shows a spinner over the chart (or in place of it without data).

func (*HeatmapW) Mirror

func (b *HeatmapW) Mirror() *T

Mirror draws the plot right to left: the x axis runs from the right, the value axis sits on the right, bars, lines, areas and points are mirrored (so categories read in reverse order), and pie, donut, radar and gauge start at the mirrored angle and sweep counter-clockwise. Labels stay readable; only their positions move. Without it the plot is drawn left to right even in RTL scopes, while the legend, tooltip and labels follow the scope direction.

func (*HeatmapW) NoTooltip

func (b *HeatmapW) NoTooltip() *T

NoTooltip disables the hover tooltip and crosshair.

func (*HeatmapW) Ramp

func (w *HeatmapW) Ramp(cs ...Color) *HeatmapW

Ramp overrides the sequential palette (low → high).

func (*HeatmapW) Show

func (w *HeatmapW) Show() View

Show builds the chart.

func (*HeatmapW) Style

func (b *HeatmapW) Style(fn func(*Style)) *T

Style tweaks the resolved chart style for this chart only.

func (*HeatmapW) Value

func (w *HeatmapW) Value(field string) *HeatmapW

Value sets the numeric field mapped to color.

func (*HeatmapW) X

func (w *HeatmapW) X(field string) *HeatmapW

X sets the column category field.

func (*HeatmapW) Y

func (w *HeatmapW) Y(field string) *HeatmapW

Y sets the row category field (first category on top).

type Labels

type Labels struct {
	Year  func(y int) string // "2026年" / "2026"
	Month func(m int) string // "2月" / "Feb"
}

Labels formats the calendar parts of time tick labels.

func LabelsOf

func LabelsOf(l *ui.Locale) Labels

LabelsOf takes the time label texts from a ui locale.

type LegendPos

type LegendPos uint8

LegendPos places the legend.

const (
	LegendAuto   LegendPos = iota // style default (Ant: top-left, Element: top-centre)
	LegendTop                     // above the plot, aligned by Style.LegendAlign
	LegendBottom                  // below the plot, centred
	LegendRight                   // inline end of the plot (left in RTL scopes), vertically centred
	LegendLeft                    // inline start of the plot (right in RTL scopes)
	LegendNone                    // hidden
)

type LineW

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

LineW builds a line or area chart.

func Area

func Area(c *ui.Context, data []Row) *LineW

Area starts an area chart (a line chart with the area filled).

func Line

func Line(c *ui.Context, data []Row) *LineW

Line starts a line chart over rows.

chart.Line(c, rows).X("month").Y("value").Series("city").Smooth().Show()

func (*LineW) A11yLabel

func (b *LineW) A11yLabel(s string) *T

A11yLabel sets the accessible name of the chart (default: its title or the localized chart kind, e.g. "折线图").

func (*LineW) Animate

func (b *LineW) Animate(on bool) *T

Animate enables (default) or disables entry and update transitions.

func (*LineW) Area

func (w *LineW) Area() *LineW

Area fills the area below each line.

func (*LineW) Colors

func (b *LineW) Colors(cs ...theme.Color) *T

Colors overrides the palette.

func (*LineW) Format

func (b *LineW) Format(f Formatter) *T

Format sets the value formatter used by the value axis, tooltip and labels (default: thousands separators).

func (*LineW) Height

func (b *LineW) Height(h float32) *T

Height sets the chart height in logical pixels (the width follows the parent).

func (*LineW) Key

func (b *LineW) Key(k any) *T

Key gives the chart a stable identity (legend and animation state) when charts are added or removed around it.

func (*LineW) Label

func (b *LineW) Label() *T

Label shows data labels on the marks.

func (*LineW) Layout

func (b *LineW) Layout(o ...layout.Option) *T

Layout applies layout options to the chart box (Grow, Margin ...).

func (*LineW) Legend

func (b *LineW) Legend(p LegendPos) *T

Legend places (or with LegendNone hides) the legend.

func (*LineW) Loading

func (b *LineW) Loading(on bool) *T

Loading shows a spinner over the chart (or in place of it without data).

func (*LineW) Log

func (w *LineW) Log() *LineW

Log uses a logarithmic value axis.

func (*LineW) Mirror

func (b *LineW) Mirror() *T

Mirror draws the plot right to left: the x axis runs from the right, the value axis sits on the right, bars, lines, areas and points are mirrored (so categories read in reverse order), and pie, donut, radar and gauge start at the mirrored angle and sweep counter-clockwise. Labels stay readable; only their positions move. Without it the plot is drawn left to right even in RTL scopes, while the legend, tooltip and labels follow the scope direction.

func (*LineW) NoTooltip

func (b *LineW) NoTooltip() *T

NoTooltip disables the hover tooltip and crosshair.

func (*LineW) NoZero

func (o *LineW) NoZero() *T

NoZero lets the value axis start near the data instead of at zero.

func (*LineW) Points

func (w *LineW) Points() *LineW

Points draws a symbol at every data point.

func (*LineW) Series

func (o *LineW) Series(field string) *T

Series sets the field that splits rows into series (legend, colors).

func (*LineW) Show

func (w *LineW) Show() View

Show builds the chart.

func (*LineW) Smooth

func (w *LineW) Smooth() *LineW

Smooth draws monotone curves instead of straight segments.

func (*LineW) Stack

func (w *LineW) Stack() *LineW

Stack stacks the series (stacked area when combined with Area).

func (*LineW) Step

func (w *LineW) Step(mode ...StepMode) *LineW

Step draws a step line (default StepEnd: horizontal, then vertical).

func (*LineW) Style

func (b *LineW) Style(fn func(*Style)) *T

Style tweaks the resolved chart style for this chart only.

func (*LineW) X

func (o *LineW) X(field string) *T

X sets the x (category / time / number) field.

func (*LineW) Y

func (o *LineW) Y(field string) *T

Y sets the value field.

func (*LineW) YMax

func (o *LineW) YMax(v float64) *T

YMax fixes the upper end of the value axis.

func (*LineW) YMin

func (o *LineW) YMin(v float64) *T

YMin fixes the lower end of the value axis.

type Linear

type Linear struct {
	D0, D1 float64
	R0, R1 float64
}

Linear maps the domain [D0, D1] onto the range [R0, R1].

func (Linear) Invert

func (s Linear) Invert(p float64) float64

Invert returns the domain value at range position p.

func (Linear) Map

func (s Linear) Map(v float64) float64

Map returns the range position of v.

func (*Linear) Nice

func (s *Linear) Nice(count int) float64

Nice extends the domain outward to nice round values and returns the tick step.

func (Linear) Ticks

func (s Linear) Ticks(count int) []float64

Ticks returns about count nice tick values inside the domain.

type LiquidW

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

LiquidW builds a liquid fill (water wave) gauge.

func Liquid

func Liquid(c *ui.Context, ratio float64) *LiquidW

Liquid starts a water wave gauge at ratio 0..1.

func (*LiquidW) A11yLabel

func (b *LiquidW) A11yLabel(s string) *T

A11yLabel sets the accessible name of the chart (default: its title or the localized chart kind, e.g. "折线图").

func (*LiquidW) Animate

func (b *LiquidW) Animate(on bool) *T

Animate enables (default) or disables entry and update transitions.

func (*LiquidW) Colors

func (b *LiquidW) Colors(cs ...theme.Color) *T

Colors overrides the palette.

func (*LiquidW) Format

func (b *LiquidW) Format(f Formatter) *T

Format sets the value formatter used by the value axis, tooltip and labels (default: thousands separators).

func (*LiquidW) Height

func (b *LiquidW) Height(h float32) *T

Height sets the chart height in logical pixels (the width follows the parent).

func (*LiquidW) Key

func (b *LiquidW) Key(k any) *T

Key gives the chart a stable identity (legend and animation state) when charts are added or removed around it.

func (*LiquidW) Label

func (b *LiquidW) Label() *T

Label shows data labels on the marks.

func (*LiquidW) Layout

func (b *LiquidW) Layout(o ...layout.Option) *T

Layout applies layout options to the chart box (Grow, Margin ...).

func (*LiquidW) Legend

func (b *LiquidW) Legend(p LegendPos) *T

Legend places (or with LegendNone hides) the legend.

func (*LiquidW) Loading

func (b *LiquidW) Loading(on bool) *T

Loading shows a spinner over the chart (or in place of it without data).

func (*LiquidW) Mirror

func (b *LiquidW) Mirror() *T

Mirror draws the plot right to left: the x axis runs from the right, the value axis sits on the right, bars, lines, areas and points are mirrored (so categories read in reverse order), and pie, donut, radar and gauge start at the mirrored angle and sweep counter-clockwise. Labels stay readable; only their positions move. Without it the plot is drawn left to right even in RTL scopes, while the legend, tooltip and labels follow the scope direction.

func (*LiquidW) NoTooltip

func (b *LiquidW) NoTooltip() *T

NoTooltip disables the hover tooltip and crosshair.

func (*LiquidW) Show

func (w *LiquidW) Show() View

Show builds the chart.

func (*LiquidW) Still

func (w *LiquidW) Still() *LiquidW

Still stops the wave motion (static screenshots, reduced motion).

func (*LiquidW) Style

func (b *LiquidW) Style(fn func(*Style)) *T

Style tweaks the resolved chart style for this chart only.

func (*LiquidW) Title

func (w *LiquidW) Title(s string) *LiquidW

Title sets the caption under the percentage.

type Log

type Log struct {
	D0, D1 float64 // > 0
	R0, R1 float64
	Base   float64 // 0 means 10
}

Log maps a positive domain logarithmically onto the range.

func (Log) Map

func (s Log) Map(v float64) float64

Map returns the range position of v (values <= 0 clamp to the low end).

func (*Log) Nice

func (s *Log) Nice()

Nice extends the domain to whole powers of the base.

func (Log) Ticks

func (s Log) Ticks() []float64

Ticks returns the powers of the base inside the domain (and 2×, 5× steps when the domain spans fewer than three decades).

type Marker

type Marker uint8

Marker is a legend / tooltip marker shape.

const (
	MarkerCircle    Marker = iota // dot (G2)
	MarkerRoundRect               // 25×14 rounded rect (ECharts)
	MarkerLine                    // line with a hollow dot (ECharts line series)
	MarkerSquare
)

type PieW

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

PieW builds a pie or donut chart.

func Donut

func Donut(c *ui.Context, data []Row) *PieW

Donut starts a donut (ring) chart with a centre statistic.

func Pie

func Pie(c *ui.Context, data []Row) *PieW

Pie starts a pie chart: Angle is the value field, Color the slice name field. Rows with the same name are summed.

chart.Pie(c, rows).Angle("value").Color("type").Inner(0.6).Show()

func (*PieW) A11yLabel

func (b *PieW) A11yLabel(s string) *T

A11yLabel sets the accessible name of the chart (default: its title or the localized chart kind, e.g. "折线图").

func (*PieW) Angle

func (w *PieW) Angle(field string) *PieW

Angle sets the value field.

func (*PieW) Animate

func (b *PieW) Animate(on bool) *T

Animate enables (default) or disables entry and update transitions.

func (*PieW) Center

func (w *PieW) Center(title, value string) *PieW

Center sets the donut centre statistic (default: total of the visible slices; empty strings hide it).

func (*PieW) Color

func (w *PieW) Color(field string) *PieW

Color sets the slice name field.

func (*PieW) Colors

func (b *PieW) Colors(cs ...theme.Color) *T

Colors overrides the palette.

func (*PieW) Format

func (b *PieW) Format(f Formatter) *T

Format sets the value formatter used by the value axis, tooltip and labels (default: thousands separators).

func (*PieW) Height

func (b *PieW) Height(h float32) *T

Height sets the chart height in logical pixels (the width follows the parent).

func (*PieW) Inner

func (w *PieW) Inner(r float64) *PieW

Inner sets the hole radius as a fraction of the outer radius (donut).

func (*PieW) InnerLabel

func (w *PieW) InnerLabel() *PieW

InnerLabel draws percentages inside the slices instead of outer labels.

func (*PieW) Key

func (b *PieW) Key(k any) *T

Key gives the chart a stable identity (legend and animation state) when charts are added or removed around it.

func (*PieW) Label

func (b *PieW) Label() *T

Label shows data labels on the marks.

func (*PieW) Layout

func (b *PieW) Layout(o ...layout.Option) *T

Layout applies layout options to the chart box (Grow, Margin ...).

func (*PieW) Legend

func (b *PieW) Legend(p LegendPos) *T

Legend places (or with LegendNone hides) the legend.

func (*PieW) Loading

func (b *PieW) Loading(on bool) *T

Loading shows a spinner over the chart (or in place of it without data).

func (*PieW) Mirror

func (b *PieW) Mirror() *T

Mirror draws the plot right to left: the x axis runs from the right, the value axis sits on the right, bars, lines, areas and points are mirrored (so categories read in reverse order), and pie, donut, radar and gauge start at the mirrored angle and sweep counter-clockwise. Labels stay readable; only their positions move. Without it the plot is drawn left to right even in RTL scopes, while the legend, tooltip and labels follow the scope direction.

func (*PieW) NoLabel

func (w *PieW) NoLabel() *PieW

NoLabel hides the outer labels and their leader lines.

func (*PieW) NoTooltip

func (b *PieW) NoTooltip() *T

NoTooltip disables the hover tooltip and crosshair.

func (*PieW) Show

func (w *PieW) Show() View

Show builds the chart.

func (*PieW) Style

func (b *PieW) Style(fn func(*Style)) *T

Style tweaks the resolved chart style for this chart only.

type Point

type Point struct {
	N       int
	R0, R1  float64
	Padding float64
}

Point places categories at evenly spaced points (lines over categories). Padding is the fraction of a step left before the first and after the last point: 0 puts them on the edges, 0.5 on band centres.

func (Point) Index

func (s Point) Index(p float64) int

Index returns the point nearest to p.

func (Point) Map

func (s Point) Map(i int) float64

Map returns the position of point i.

type Polar

type Polar struct {
	Center       geom.Point
	Inner, Outer float32
	Start, Sweep float64
}

Polar maps (t, r) — t the fraction of the sweep, r the fraction between Inner and Outer — to pixels. Start is the angle of t = 0 in radians (y-down, so -π/2 is 12 o'clock) and Sweep the total angle (2π clockwise for a full circle).

func NewPolar

func NewPolar(r geom.Rect, inner float64) Polar

NewPolar centres a full clockwise circle starting at 12 o'clock in r.

func (Polar) Angle

func (p Polar) Angle(t float64) float64

Angle returns the angle of t.

func (Polar) At

func (p Polar) At(t, r float64) geom.Point

At returns the pixel position of (t, r).

func (Polar) Locate

func (p Polar) Locate(pt geom.Point) (t float64, dist float32)

Locate inverts At: t in [0,1) for full circles, and the pixel distance from the centre.

func (Polar) Mirrored

func (p Polar) Mirrored() Polar

Mirrored returns p reflected about the vertical line through its centre: the start angle is mirrored (θ → π − θ) and the sweep reversed, so a clockwise chart becomes counter-clockwise.

func (Polar) Radius

func (p Polar) Radius(r float64) float32

Radius returns the pixel radius of r.

type RadarW

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

RadarW builds a radar (spider) chart.

func Radar

func Radar(c *ui.Context, data []Row) *RadarW

Radar starts a radar chart: X is the dimension field, Y the value.

chart.Radar(c, rows).X("item").Y("score").Series("user").Show()

func (*RadarW) A11yLabel

func (b *RadarW) A11yLabel(s string) *T

A11yLabel sets the accessible name of the chart (default: its title or the localized chart kind, e.g. "折线图").

func (*RadarW) Animate

func (b *RadarW) Animate(on bool) *T

Animate enables (default) or disables entry and update transitions.

func (*RadarW) Circle

func (w *RadarW) Circle() *RadarW

Circle draws a circular grid instead of polygons.

func (*RadarW) Colors

func (b *RadarW) Colors(cs ...theme.Color) *T

Colors overrides the palette.

func (*RadarW) Format

func (b *RadarW) Format(f Formatter) *T

Format sets the value formatter used by the value axis, tooltip and labels (default: thousands separators).

func (*RadarW) Height

func (b *RadarW) Height(h float32) *T

Height sets the chart height in logical pixels (the width follows the parent).

func (*RadarW) Key

func (b *RadarW) Key(k any) *T

Key gives the chart a stable identity (legend and animation state) when charts are added or removed around it.

func (*RadarW) Label

func (b *RadarW) Label() *T

Label shows data labels on the marks.

func (*RadarW) Layout

func (b *RadarW) Layout(o ...layout.Option) *T

Layout applies layout options to the chart box (Grow, Margin ...).

func (*RadarW) Legend

func (b *RadarW) Legend(p LegendPos) *T

Legend places (or with LegendNone hides) the legend.

func (*RadarW) Loading

func (b *RadarW) Loading(on bool) *T

Loading shows a spinner over the chart (or in place of it without data).

func (*RadarW) Mirror

func (b *RadarW) Mirror() *T

Mirror draws the plot right to left: the x axis runs from the right, the value axis sits on the right, bars, lines, areas and points are mirrored (so categories read in reverse order), and pie, donut, radar and gauge start at the mirrored angle and sweep counter-clockwise. Labels stay readable; only their positions move. Without it the plot is drawn left to right even in RTL scopes, while the legend, tooltip and labels follow the scope direction.

func (*RadarW) NoArea

func (w *RadarW) NoArea() *RadarW

NoArea draws outlines only.

func (*RadarW) NoTooltip

func (b *RadarW) NoTooltip() *T

NoTooltip disables the hover tooltip and crosshair.

func (*RadarW) NoZero

func (o *RadarW) NoZero() *T

NoZero lets the value axis start near the data instead of at zero.

func (*RadarW) Series

func (o *RadarW) Series(field string) *T

Series sets the field that splits rows into series (legend, colors).

func (*RadarW) Show

func (w *RadarW) Show() View

Show builds the chart.

func (*RadarW) Style

func (b *RadarW) Style(fn func(*Style)) *T

Style tweaks the resolved chart style for this chart only.

func (*RadarW) X

func (o *RadarW) X(field string) *T

X sets the x (category / time / number) field.

func (*RadarW) Y

func (o *RadarW) Y(field string) *T

Y sets the value field.

func (*RadarW) YMax

func (o *RadarW) YMax(v float64) *T

YMax fixes the upper end of the value axis.

func (*RadarW) YMin

func (o *RadarW) YMin(v float64) *T

YMin fixes the lower end of the value axis.

type Row

type Row = map[string]any

Row is one datum: field name to value. Values may be any Go number, string (category), time.Time, or nil (missing).

func RowsOf

func RowsOf[T any](items []T, fn func(T) Row) []Row

RowsOf converts typed items to rows.

rows := chart.RowsOf(sales, func(s Sale) chart.Row {
	return chart.Row{"month": s.Month, "value": s.Amount}
})

type ScatterW

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

ScatterW builds a scatter or bubble chart.

func Bubble

func Bubble(c *ui.Context, data []Row) *ScatterW

Bubble starts a bubble chart: Size maps a field to the bubble area.

func Scatter

func Scatter(c *ui.Context, data []Row) *ScatterW

Scatter starts a scatter chart; X and Y are numeric fields.

chart.Scatter(c, rows).X("height").Y("weight").Series("gender").Show()

func (*ScatterW) A11yLabel

func (b *ScatterW) A11yLabel(s string) *T

A11yLabel sets the accessible name of the chart (default: its title or the localized chart kind, e.g. "折线图").

func (*ScatterW) Animate

func (b *ScatterW) Animate(on bool) *T

Animate enables (default) or disables entry and update transitions.

func (*ScatterW) Colors

func (b *ScatterW) Colors(cs ...theme.Color) *T

Colors overrides the palette.

func (*ScatterW) Format

func (b *ScatterW) Format(f Formatter) *T

Format sets the value formatter used by the value axis, tooltip and labels (default: thousands separators).

func (*ScatterW) Height

func (b *ScatterW) Height(h float32) *T

Height sets the chart height in logical pixels (the width follows the parent).

func (*ScatterW) Key

func (b *ScatterW) Key(k any) *T

Key gives the chart a stable identity (legend and animation state) when charts are added or removed around it.

func (*ScatterW) Label

func (b *ScatterW) Label() *T

Label shows data labels on the marks.

func (*ScatterW) Layout

func (b *ScatterW) Layout(o ...layout.Option) *T

Layout applies layout options to the chart box (Grow, Margin ...).

func (*ScatterW) Legend

func (b *ScatterW) Legend(p LegendPos) *T

Legend places (or with LegendNone hides) the legend.

func (*ScatterW) Loading

func (b *ScatterW) Loading(on bool) *T

Loading shows a spinner over the chart (or in place of it without data).

func (*ScatterW) Mirror

func (b *ScatterW) Mirror() *T

Mirror draws the plot right to left: the x axis runs from the right, the value axis sits on the right, bars, lines, areas and points are mirrored (so categories read in reverse order), and pie, donut, radar and gauge start at the mirrored angle and sweep counter-clockwise. Labels stay readable; only their positions move. Without it the plot is drawn left to right even in RTL scopes, while the legend, tooltip and labels follow the scope direction.

func (*ScatterW) NoTooltip

func (b *ScatterW) NoTooltip() *T

NoTooltip disables the hover tooltip and crosshair.

func (*ScatterW) NoZero

func (o *ScatterW) NoZero() *T

NoZero lets the value axis start near the data instead of at zero.

func (*ScatterW) Radius

func (w *ScatterW) Radius(min, max float32) *ScatterW

Radius sets the bubble radius range (default 4..24, points 4).

func (*ScatterW) Series

func (o *ScatterW) Series(field string) *T

Series sets the field that splits rows into series (legend, colors).

func (*ScatterW) Show

func (w *ScatterW) Show() View

Show builds the chart.

func (*ScatterW) Size

func (w *ScatterW) Size(field string) *ScatterW

Size maps a numeric field to the point area (bubbles).

func (*ScatterW) Style

func (b *ScatterW) Style(fn func(*Style)) *T

Style tweaks the resolved chart style for this chart only.

func (*ScatterW) X

func (o *ScatterW) X(field string) *T

X sets the x (category / time / number) field.

func (*ScatterW) XFormat

func (w *ScatterW) XFormat(f Formatter) *ScatterW

XFormat formats x tick labels and tooltip values.

func (*ScatterW) Y

func (o *ScatterW) Y(field string) *T

Y sets the value field.

func (*ScatterW) YMax

func (o *ScatterW) YMax(v float64) *T

YMax fixes the upper end of the value axis.

func (*ScatterW) YMin

func (o *ScatterW) YMin(v float64) *T

YMin fixes the lower end of the value axis.

func (*ScatterW) Zero

func (w *ScatterW) Zero() *ScatterW

Zero includes zero in both axes.

type StepMode

type StepMode uint8

StepMode selects a step line shape.

const (
	StepNone   StepMode = iota
	StepEnd             // horizontal then vertical ("hv")
	StepStart           // vertical then horizontal ("vh")
	StepMiddle          // change halfway between points ("hvh")
)

type Style

type Style struct {
	Name string

	Colors     []theme.Color // categorical palette, cycled
	Sequential []theme.Color // low → high (heatmap, continuous legend)

	Font      float32     // axis / legend text size
	Label     theme.Color // axis tick labels
	Title     theme.Color // axis titles, statistic captions
	AxisLine  theme.Color // axis base line
	Tick      theme.Color // tick marks
	Grid      theme.Color // grid lines
	GridDash  []float32   // nil = solid
	XAxisLine bool        // draw the bottom axis line (G2 relies on the 0 grid line)
	YAxisLine bool
	TickLen   float32 // 0 hides tick marks
	LabelGap  float32 // tick (or axis) to label

	LegendPos    LegendPos // default placement for multi-series charts
	LegendCenter bool      // centre a top legend (ECharts)
	LegendText   theme.Color
	LegendOff    theme.Color // hidden series
	LegendMarker Marker
	LegendGap    float32 // between items

	TooltipBg     theme.Color
	TooltipTitle  theme.Color
	TooltipName   theme.Color
	TooltipValue  theme.Color
	TooltipFont   float32
	TooltipPad    float32
	TooltipRadius float32
	TooltipShadow []paint.Shadow
	TooltipBold   bool // bold values (ECharts)
	TooltipLine   float32

	Crosshair     theme.Color
	CrosshairDash []float32
	BandHover     theme.Color // background of the hovered band (bars)

	Surface     theme.Color // chart background, used for halo strokes
	LineWidth   float32
	ShowPoints  bool    // draw hollow symbols on lines (ECharts default)
	PointRadius float32 // symbol radius
	AreaOpacity float64 // flat area fill opacity
	AreaGrad    bool    // fade area fills to transparent (G2 look)
	BarPadding  float64 // inner band padding
	BarOuter    float64 // outer band padding
	BarRadius   float32
	PointPad    bool    // lines over categories sit on band centres (ECharts boundaryGap)
	SliceStroke float32 // white separators between pie slices
	Track       theme.Color
	Positive    theme.Color
	Negative    theme.Color
}

Style is the visual language of charts: palette, axis, legend and tooltip tokens. StyleOf derives it from the UI theme; RegisterStyle adds new design languages (a shadcn style, a brand palette) without touching the charts.

func AntStyle

func AntStyle(th *theme.Theme) *Style

AntStyle is the G2 (Ant Design Charts v2) look derived from an Ant theme.

func EChartsStyle

func EChartsStyle(th *theme.Theme) *Style

EChartsStyle is the ECharts 5 default look, used for Element Plus.

func ShadcnStyle

func ShadcnStyle(th *theme.Theme) *Style

ShadcnStyle is the shadcn/ui chart look (Recharts with shadcn's chart conventions): the --chart-1 … --chart-5 palette, horizontal grid lines only, no axis or tick lines, 12px muted labels, a bordered rounded tooltip with square markers, rounded bars and gradient areas. It is registered for theme.StyleShadcn themes.

func StyleOf

func StyleOf(th *theme.Theme) *Style

StyleOf returns the chart style for th.

func (*Style) Color

func (s *Style) Color(i int) theme.Color

Color returns palette color i (cycled).

type StyleFunc

type StyleFunc func(th *theme.Theme) *Style

StyleFunc derives a chart style from a UI theme.

type TimeScale

type TimeScale struct {
	D0, D1 time.Time
	R0, R1 float64
}

TimeScale maps a time domain onto the range.

func (TimeScale) Map

func (s TimeScale) Map(t time.Time) float64

Map returns the range position of t.

func (TimeScale) Ticks

func (s TimeScale) Ticks(count int, loc Labels) []TimeTick

Ticks returns about count calendar-aligned ticks with labels.

type TimeTick

type TimeTick struct {
	T     time.Time
	Label string
	Major bool // a coarser boundary (new year, month or day)
}

TimeTick is one time tick with its label.

func TimeTicks

func TimeTicks(t0, t1 time.Time, count int, lb Labels) []TimeTick

TimeTicks returns calendar-aligned ticks inside [t0, t1] at an automatic granularity. Labels are hierarchical: a tick that starts a new year shows the year, one that starts a new month (on day ticks) the month, and so on.

type TimeUnit

type TimeUnit uint8

TimeUnit is a tick granularity.

const (
	Second TimeUnit = iota
	Minute
	Hour
	Day
	Week
	Month
	Year
)

func TimeInterval

func TimeInterval(t0, t1 time.Time, count int) (TimeUnit, int)

TimeInterval picks the granularity giving at most about count ticks over [t0, t1].

type TinyW

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

TinyW builds a sparkline for statistic cards: no axes or legend, a compact tooltip on hover.

func TinyArea

func TinyArea(c *ui.Context, vals []float64) *TinyW

TinyArea starts a filled sparkline.

func TinyColumn

func TinyColumn(c *ui.Context, vals []float64) *TinyW

TinyColumn starts a mini column chart.

func TinyLine

func TinyLine(c *ui.Context, vals []float64) *TinyW

TinyLine starts a sparkline.

func TinyProgress

func TinyProgress(c *ui.Context, ratio float64) *TinyW

TinyProgress starts a thin progress bar (ratio 0..1).

func (*TinyW) A11yLabel

func (b *TinyW) A11yLabel(s string) *T

A11yLabel sets the accessible name of the chart (default: its title or the localized chart kind, e.g. "折线图").

func (*TinyW) Animate

func (b *TinyW) Animate(on bool) *T

Animate enables (default) or disables entry and update transitions.

func (*TinyW) Color

func (w *TinyW) Color(col theme.Color) *TinyW

Color sets the mark color (default: first palette color).

func (*TinyW) Colors

func (b *TinyW) Colors(cs ...theme.Color) *T

Colors overrides the palette.

func (*TinyW) Format

func (b *TinyW) Format(f Formatter) *T

Format sets the value formatter used by the value axis, tooltip and labels (default: thousands separators).

func (*TinyW) Height

func (b *TinyW) Height(h float32) *T

Height sets the chart height in logical pixels (the width follows the parent).

func (*TinyW) Key

func (b *TinyW) Key(k any) *T

Key gives the chart a stable identity (legend and animation state) when charts are added or removed around it.

func (*TinyW) Label

func (b *TinyW) Label() *T

Label shows data labels on the marks.

func (*TinyW) Layout

func (b *TinyW) Layout(o ...layout.Option) *T

Layout applies layout options to the chart box (Grow, Margin ...).

func (*TinyW) Legend

func (b *TinyW) Legend(p LegendPos) *T

Legend places (or with LegendNone hides) the legend.

func (*TinyW) Loading

func (b *TinyW) Loading(on bool) *T

Loading shows a spinner over the chart (or in place of it without data).

func (*TinyW) Mirror

func (b *TinyW) Mirror() *T

Mirror draws the plot right to left: the x axis runs from the right, the value axis sits on the right, bars, lines, areas and points are mirrored (so categories read in reverse order), and pie, donut, radar and gauge start at the mirrored angle and sweep counter-clockwise. Labels stay readable; only their positions move. Without it the plot is drawn left to right even in RTL scopes, while the legend, tooltip and labels follow the scope direction.

func (*TinyW) Names

func (w *TinyW) Names(names ...string) *TinyW

Names labels the points in the tooltip (e.g. dates).

func (*TinyW) NoTooltip

func (b *TinyW) NoTooltip() *T

NoTooltip disables the hover tooltip and crosshair.

func (*TinyW) Show

func (w *TinyW) Show() View

Show builds the chart.

func (*TinyW) Smooth

func (w *TinyW) Smooth() *TinyW

Smooth draws the line as a monotone curve.

func (*TinyW) Style

func (b *TinyW) Style(fn func(*Style)) *T

Style tweaks the resolved chart style for this chart only.

func (*TinyW) Target

func (w *TinyW) Target(v float64) *TinyW

Target draws a marker line at a target value (progress: ratio).

type Tip

type Tip struct {
	Title string
	Items []TipItem
	Index int // x / category / slice index
}

Tip is the content of a tooltip.

type TipItem

type TipItem struct {
	Name, Value string
	Color       theme.Color
	Marker      Marker
}

TipItem is one tooltip row.

type View

type View struct {
	*ui.Box
	// contains filtered or unexported fields
}

View is a shown chart: its box plus the hover / legend state of the frame.

func (View) Hidden

func (v View) Hidden(name string) bool

Hidden reports whether the legend has hidden series (or slice) name.

func (View) Tooltip

func (v View) Tooltip() (Tip, bool)

Tooltip returns the tooltip shown in this frame.

Jump to

Keyboard shortcuts

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