Skip to content

chart 实验性 ​

实验性

本包属于实验层:任何 0.x 版本都可能有不兼容变化(docs/release.md「API 稳定性」)。

go
import "github.com/tangoui/tango/ui/chart"

本页由 site/tools/apigen 从源码注释生成(按 darwin 构建标签选文件),请勿手改。

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 稳定性").

函数 ​

func DataTable ​

go
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 ​

go
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 ​

go
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 ​

go
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 ​

go
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 ​

go
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 ​

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

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

func Num ​

go
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 ​

go
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 ​

go
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 ​

go
func Str(v any) string

Str converts a field value to its category label.

func TimeOf ​

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

TimeOf converts a field value to a time.

类型 ​

Band ​

go
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 ​

go
func (s Band) Bandwidth() float64

Bandwidth returns the width of one band.

func (Band) Center ​

go
func (s Band) Center(i int) float64

Center returns the middle of band i.

func (Band) Index ​

go
func (s Band) Index(p float64) int

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

func (Band) Map ​

go
func (s Band) Map(i int) float64

Map returns the start of band i.

func (Band) Step ​

go
func (s Band) Step() float64

Step returns the distance between band starts.

Cartesian ​

go
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 ​

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

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

func (Cartesian) HX ​

go
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 ​

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

Norm inverts At.

func (Cartesian) Rect ​

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

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

Color ​

go
type Color = theme.Color

Color is a theme color (ramps, overrides).

ColumnW ​

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

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

func Bar ​

go
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 ​

go
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 ​

go
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 ​

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

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

func (*ColumnW) Colors ​

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

Colors overrides the palette.

func (*ColumnW) Format ​

go
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 ​

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

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

func (*ColumnW) Key ​

go
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 ​

go
func (b *ColumnW) Label() *T

Label shows data labels on the marks.

func (*ColumnW) Layout ​

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

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

func (*ColumnW) Legend ​

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

Legend places (or with LegendNone hides) the legend.

func (*ColumnW) Loading ​

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

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

func (*ColumnW) MaxWidth ​

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

MaxWidth caps the bar thickness.

func (*ColumnW) Mirror ​

go
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 ​

go
func (b *ColumnW) NoTooltip() *T

NoTooltip disables the hover tooltip and crosshair.

func (*ColumnW) NoZero ​

go
func (o *ColumnW) NoZero() *T

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

func (*ColumnW) Padding ​

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

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

func (*ColumnW) Percent ​

go
func (w *ColumnW) Percent() *ColumnW

Percent stacks the series normalised to 100%.

func (*ColumnW) Radius ​

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

Radius rounds the bar ends.

func (*ColumnW) Series ​

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

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

func (*ColumnW) Show ​

go
func (w *ColumnW) Show() View

Show builds the chart.

func (*ColumnW) Stack ​

go
func (w *ColumnW) Stack() *ColumnW

Stack stacks the series.

func (*ColumnW) Style ​

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

Style tweaks the resolved chart style for this chart only.

func (*ColumnW) X ​

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

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

func (*ColumnW) Y ​

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

Y sets the value field.

func (*ColumnW) YMax ​

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

YMax fixes the upper end of the value axis.

func (*ColumnW) YMin ​

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

YMin fixes the lower end of the value axis.

DualW ​

go
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 ​

go
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 ​

go
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 ​

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

Alias sets the legend / tooltip name of a field.

func (*DualW) Animate ​

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

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

func (*DualW) Colors ​

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

Colors overrides the palette.

func (*DualW) Column ​

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

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

func (*DualW) Format ​

go
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 ​

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

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

func (*DualW) Key ​

go
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 ​

go
func (b *DualW) Label() *T

Label shows data labels on the marks.

func (*DualW) Layout ​

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

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

func (*DualW) Legend ​

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

Legend places (or with LegendNone hides) the legend.

func (*DualW) Line ​

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

Line adds fields drawn as lines on the right axis.

func (*DualW) LineFormat ​

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

LineFormat formats the right axis and line values.

func (*DualW) Loading ​

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

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

func (*DualW) Mirror ​

go
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 ​

go
func (b *DualW) NoTooltip() *T

NoTooltip disables the hover tooltip and crosshair.

func (*DualW) Show ​

go
func (w *DualW) Show() View

Show builds the chart.

func (*DualW) Smooth ​

go
func (w *DualW) Smooth() *DualW

Smooth draws the lines as monotone curves.

func (*DualW) Style ​

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

Style tweaks the resolved chart style for this chart only.

func (*DualW) X ​

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

X sets the category field.

Formatter ​

go
type Formatter func(v float64) string

Formatter turns a value into a label.

func Compact ​

go
func Compact(locale string) Formatter

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

func Percent ​

go
func Percent(decimals int) Formatter

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

func Thousands ​

go
func Thousands(decimals int) Formatter

Thousands returns a formatter with thousands separators.

func Unit ​

go
func Unit(unit string, decimals int) Formatter

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

FunnelW ​

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

FunnelW builds a funnel chart.

func Funnel ​

go
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 ​

go
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 ​

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

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

func (*FunnelW) Colors ​

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

Colors overrides the palette.

func (*FunnelW) Format ​

go
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 ​

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

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

func (*FunnelW) Key ​

go
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 ​

go
func (b *FunnelW) Label() *T

Label shows data labels on the marks.

func (*FunnelW) Layout ​

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

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

func (*FunnelW) Legend ​

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

Legend places (or with LegendNone hides) the legend.

func (*FunnelW) Loading ​

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

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

func (*FunnelW) Mirror ​

go
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 ​

go
func (w *FunnelW) NoConversion() *FunnelW

NoConversion hides the stage-to-stage conversion rates.

func (*FunnelW) NoTooltip ​

go
func (b *FunnelW) NoTooltip() *T

NoTooltip disables the hover tooltip and crosshair.

func (*FunnelW) Show ​

go
func (w *FunnelW) Show() View

Show builds the chart.

func (*FunnelW) Style ​

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

Style tweaks the resolved chart style for this chart only.

func (*FunnelW) X ​

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

X sets the stage field.

func (*FunnelW) Y ​

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

Y sets the value field.

GaugeW ​

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

GaugeW builds a gauge (dial) chart.

func Gauge ​

go
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 ​

go
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 ​

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

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

func (*GaugeW) Bands ​

go
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 ​

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

Colors overrides the palette.

func (*GaugeW) Format ​

go
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 ​

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

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

func (*GaugeW) Key ​

go
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 ​

go
func (b *GaugeW) Label() *T

Label shows data labels on the marks.

func (*GaugeW) Layout ​

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

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

func (*GaugeW) Legend ​

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

Legend places (or with LegendNone hides) the legend.

func (*GaugeW) Loading ​

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

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

func (*GaugeW) Mirror ​

go
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 ​

go
func (b *GaugeW) NoTooltip() *T

NoTooltip disables the hover tooltip and crosshair.

func (*GaugeW) Range ​

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

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

func (*GaugeW) Show ​

go
func (w *GaugeW) Show() View

Show builds the chart.

func (*GaugeW) Style ​

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

Style tweaks the resolved chart style for this chart only.

func (*GaugeW) Title ​

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

Title sets the caption under the value.

HeatmapW ​

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

HeatmapW builds a heatmap over two category fields.

func Heatmap ​

go
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 ​

go
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 ​

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

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

func (*HeatmapW) Colors ​

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

Colors overrides the palette.

func (*HeatmapW) Format ​

go
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 ​

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

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

func (*HeatmapW) Key ​

go
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 ​

go
func (b *HeatmapW) Label() *T

Label shows data labels on the marks.

func (*HeatmapW) Layout ​

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

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

func (*HeatmapW) Legend ​

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

Legend places (or with LegendNone hides) the legend.

func (*HeatmapW) Loading ​

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

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

func (*HeatmapW) Mirror ​

go
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 ​

go
func (b *HeatmapW) NoTooltip() *T

NoTooltip disables the hover tooltip and crosshair.

func (*HeatmapW) Ramp ​

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

Ramp overrides the sequential palette (low → high).

func (*HeatmapW) Show ​

go
func (w *HeatmapW) Show() View

Show builds the chart.

func (*HeatmapW) Style ​

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

Style tweaks the resolved chart style for this chart only.

func (*HeatmapW) Value ​

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

Value sets the numeric field mapped to color.

func (*HeatmapW) X ​

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

X sets the column category field.

func (*HeatmapW) Y ​

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

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

Labels ​

go
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 ​

go
func LabelsOf(l *ui.Locale) Labels

LabelsOf takes the time label texts from a ui locale.

LegendPos ​

go
type LegendPos uint8

LegendPos places the legend.

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

LineW ​

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

LineW builds a line or area chart.

func Area ​

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

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

func Line ​

go
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 ​

go
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 ​

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

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

func (*LineW) Area ​

go
func (w *LineW) Area() *LineW

Area fills the area below each line.

func (*LineW) Colors ​

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

Colors overrides the palette.

func (*LineW) Format ​

go
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 ​

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

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

func (*LineW) Key ​

go
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 ​

go
func (b *LineW) Label() *T

Label shows data labels on the marks.

func (*LineW) Layout ​

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

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

func (*LineW) Legend ​

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

Legend places (or with LegendNone hides) the legend.

func (*LineW) Loading ​

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

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

func (*LineW) Log ​

go
func (w *LineW) Log() *LineW

Log uses a logarithmic value axis.

func (*LineW) Mirror ​

go
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 ​

go
func (b *LineW) NoTooltip() *T

NoTooltip disables the hover tooltip and crosshair.

func (*LineW) NoZero ​

go
func (o *LineW) NoZero() *T

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

func (*LineW) Points ​

go
func (w *LineW) Points() *LineW

Points draws a symbol at every data point.

func (*LineW) Series ​

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

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

func (*LineW) Show ​

go
func (w *LineW) Show() View

Show builds the chart.

func (*LineW) Smooth ​

go
func (w *LineW) Smooth() *LineW

Smooth draws monotone curves instead of straight segments.

func (*LineW) Stack ​

go
func (w *LineW) Stack() *LineW

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

func (*LineW) Step ​

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

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

func (*LineW) Style ​

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

Style tweaks the resolved chart style for this chart only.

func (*LineW) X ​

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

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

func (*LineW) Y ​

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

Y sets the value field.

func (*LineW) YMax ​

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

YMax fixes the upper end of the value axis.

func (*LineW) YMin ​

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

YMin fixes the lower end of the value axis.

Linear ​

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

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

func (Linear) Invert ​

go
func (s Linear) Invert(p float64) float64

Invert returns the domain value at range position p.

func (Linear) Map ​

go
func (s Linear) Map(v float64) float64

Map returns the range position of v.

func (*Linear) Nice ​

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

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

func (Linear) Ticks ​

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

Ticks returns about count nice tick values inside the domain.

LiquidW ​

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

LiquidW builds a liquid fill (water wave) gauge.

func Liquid ​

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

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

func (*LiquidW) A11yLabel ​

go
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 ​

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

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

func (*LiquidW) Colors ​

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

Colors overrides the palette.

func (*LiquidW) Format ​

go
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 ​

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

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

func (*LiquidW) Key ​

go
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 ​

go
func (b *LiquidW) Label() *T

Label shows data labels on the marks.

func (*LiquidW) Layout ​

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

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

func (*LiquidW) Legend ​

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

Legend places (or with LegendNone hides) the legend.

func (*LiquidW) Loading ​

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

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

func (*LiquidW) Mirror ​

go
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 ​

go
func (b *LiquidW) NoTooltip() *T

NoTooltip disables the hover tooltip and crosshair.

func (*LiquidW) Show ​

go
func (w *LiquidW) Show() View

Show builds the chart.

func (*LiquidW) Still ​

go
func (w *LiquidW) Still() *LiquidW

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

func (*LiquidW) Style ​

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

Style tweaks the resolved chart style for this chart only.

func (*LiquidW) Title ​

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

Title sets the caption under the percentage.

Log ​

go
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 ​

go
func (s Log) Map(v float64) float64

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

func (*Log) Nice ​

go
func (s *Log) Nice()

Nice extends the domain to whole powers of the base.

func (Log) Ticks ​

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

Marker ​

go
type Marker uint8

Marker is a legend / tooltip marker shape.

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

PieW ​

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

PieW builds a pie or donut chart.

func Donut ​

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

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

func Pie ​

go
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 ​

go
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 ​

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

Angle sets the value field.

func (*PieW) Animate ​

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

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

func (*PieW) Center ​

go
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 ​

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

Color sets the slice name field.

func (*PieW) Colors ​

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

Colors overrides the palette.

func (*PieW) Format ​

go
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 ​

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

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

func (*PieW) Inner ​

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

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

func (*PieW) InnerLabel ​

go
func (w *PieW) InnerLabel() *PieW

InnerLabel draws percentages inside the slices instead of outer labels.

func (*PieW) Key ​

go
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 ​

go
func (b *PieW) Label() *T

Label shows data labels on the marks.

func (*PieW) Layout ​

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

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

func (*PieW) Legend ​

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

Legend places (or with LegendNone hides) the legend.

func (*PieW) Loading ​

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

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

func (*PieW) Mirror ​

go
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 ​

go
func (w *PieW) NoLabel() *PieW

NoLabel hides the outer labels and their leader lines.

func (*PieW) NoTooltip ​

go
func (b *PieW) NoTooltip() *T

NoTooltip disables the hover tooltip and crosshair.

func (*PieW) Show ​

go
func (w *PieW) Show() View

Show builds the chart.

func (*PieW) Style ​

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

Style tweaks the resolved chart style for this chart only.

Point ​

go
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 ​

go
func (s Point) Index(p float64) int

Index returns the point nearest to p.

func (Point) Map ​

go
func (s Point) Map(i int) float64

Map returns the position of point i.

Polar ​

go
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 ​

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

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

func (Polar) Angle ​

go
func (p Polar) Angle(t float64) float64

Angle returns the angle of t.

func (Polar) At ​

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

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

func (Polar) Locate ​

go
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 ​

go
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 ​

go
func (p Polar) Radius(r float64) float32

Radius returns the pixel radius of r.

RadarW ​

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

RadarW builds a radar (spider) chart.

func Radar ​

go
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 ​

go
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 ​

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

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

func (*RadarW) Circle ​

go
func (w *RadarW) Circle() *RadarW

Circle draws a circular grid instead of polygons.

func (*RadarW) Colors ​

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

Colors overrides the palette.

func (*RadarW) Format ​

go
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 ​

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

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

func (*RadarW) Key ​

go
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 ​

go
func (b *RadarW) Label() *T

Label shows data labels on the marks.

func (*RadarW) Layout ​

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

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

func (*RadarW) Legend ​

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

Legend places (or with LegendNone hides) the legend.

func (*RadarW) Loading ​

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

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

func (*RadarW) Mirror ​

go
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 ​

go
func (w *RadarW) NoArea() *RadarW

NoArea draws outlines only.

func (*RadarW) NoTooltip ​

go
func (b *RadarW) NoTooltip() *T

NoTooltip disables the hover tooltip and crosshair.

func (*RadarW) NoZero ​

go
func (o *RadarW) NoZero() *T

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

func (*RadarW) Series ​

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

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

func (*RadarW) Show ​

go
func (w *RadarW) Show() View

Show builds the chart.

func (*RadarW) Style ​

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

Style tweaks the resolved chart style for this chart only.

func (*RadarW) X ​

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

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

func (*RadarW) Y ​

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

Y sets the value field.

func (*RadarW) YMax ​

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

YMax fixes the upper end of the value axis.

func (*RadarW) YMin ​

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

YMin fixes the lower end of the value axis.

Row ​

go
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 ​

go
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}
})

ScatterW ​

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

ScatterW builds a scatter or bubble chart.

func Bubble ​

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

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

func Scatter ​

go
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 ​

go
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 ​

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

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

func (*ScatterW) Colors ​

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

Colors overrides the palette.

func (*ScatterW) Format ​

go
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 ​

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

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

func (*ScatterW) Key ​

go
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 ​

go
func (b *ScatterW) Label() *T

Label shows data labels on the marks.

func (*ScatterW) Layout ​

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

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

func (*ScatterW) Legend ​

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

Legend places (or with LegendNone hides) the legend.

func (*ScatterW) Loading ​

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

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

func (*ScatterW) Mirror ​

go
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 ​

go
func (b *ScatterW) NoTooltip() *T

NoTooltip disables the hover tooltip and crosshair.

func (*ScatterW) NoZero ​

go
func (o *ScatterW) NoZero() *T

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

func (*ScatterW) Radius ​

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

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

func (*ScatterW) Series ​

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

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

func (*ScatterW) Show ​

go
func (w *ScatterW) Show() View

Show builds the chart.

func (*ScatterW) Size ​

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

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

func (*ScatterW) Style ​

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

Style tweaks the resolved chart style for this chart only.

func (*ScatterW) X ​

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

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

func (*ScatterW) XFormat ​

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

XFormat formats x tick labels and tooltip values.

func (*ScatterW) Y ​

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

Y sets the value field.

func (*ScatterW) YMax ​

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

YMax fixes the upper end of the value axis.

func (*ScatterW) YMin ​

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

YMin fixes the lower end of the value axis.

func (*ScatterW) Zero ​

go
func (w *ScatterW) Zero() *ScatterW

Zero includes zero in both axes.

StepMode ​

go
type StepMode uint8

StepMode selects a step line shape.

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

Style ​

go
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 ​

go
func AntStyle(th *theme.Theme) *Style

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

func EChartsStyle ​

go
func EChartsStyle(th *theme.Theme) *Style

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

func ShadcnStyle ​

go
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 ​

go
func StyleOf(th *theme.Theme) *Style

StyleOf returns the chart style for th.

func (*Style) Color ​

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

Color returns palette color i (cycled).

StyleFunc ​

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

StyleFunc derives a chart style from a UI theme.

TimeScale ​

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

TimeScale maps a time domain onto the range.

func (TimeScale) Map ​

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

Map returns the range position of t.

func (TimeScale) Ticks ​

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

Ticks returns about count calendar-aligned ticks with labels.

TimeTick ​

go
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 ​

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

TimeUnit ​

go
type TimeUnit uint8

TimeUnit is a tick granularity.

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

func TimeInterval ​

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

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

TinyW ​

go
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 ​

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

TinyArea starts a filled sparkline.

func TinyColumn ​

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

TinyColumn starts a mini column chart.

func TinyLine ​

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

TinyLine starts a sparkline.

func TinyProgress ​

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

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

func (*TinyW) A11yLabel ​

go
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 ​

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

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

func (*TinyW) Color ​

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

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

func (*TinyW) Colors ​

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

Colors overrides the palette.

func (*TinyW) Format ​

go
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 ​

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

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

func (*TinyW) Key ​

go
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 ​

go
func (b *TinyW) Label() *T

Label shows data labels on the marks.

func (*TinyW) Layout ​

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

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

func (*TinyW) Legend ​

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

Legend places (or with LegendNone hides) the legend.

func (*TinyW) Loading ​

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

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

func (*TinyW) Mirror ​

go
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 ​

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

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

func (*TinyW) NoTooltip ​

go
func (b *TinyW) NoTooltip() *T

NoTooltip disables the hover tooltip and crosshair.

func (*TinyW) Show ​

go
func (w *TinyW) Show() View

Show builds the chart.

func (*TinyW) Smooth ​

go
func (w *TinyW) Smooth() *TinyW

Smooth draws the line as a monotone curve.

func (*TinyW) Style ​

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

Style tweaks the resolved chart style for this chart only.

func (*TinyW) Target ​

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

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

Tip ​

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

Tip is the content of a tooltip.

TipItem ​

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

TipItem is one tooltip row.

View ​

go
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 ​

go
func (v View) Hidden(name string) bool

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

func (View) Tooltip ​

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

Tooltip returns the tooltip shown in this frame.

以 MIT 许可发布