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 ¶
- func DataTable(c *ui.Context, rows []Row, fields ...string) *ui.TableW
- func FormatCompact(v float64, locale string) string
- func FormatNumber(v float64, decimals int) string
- func LTTB(xs, ys []float64, threshold int) []int
- func NiceDomain(lo, hi float64, count int) (nlo, nhi, step float64)
- func NiceStep(span float64, count int) float64
- func NiceTicks(lo, hi float64, count int) []float64
- func Num(v any) (float64, bool)
- func RegisterStyle(match func(*theme.Theme) bool, fn StyleFunc)
- func Stack(vals [][]float64, hidden []bool, percent bool) (lo, hi [][]float64)
- func Str(v any) string
- func TimeOf(v any) (time.Time, bool)
- type Band
- type Cartesian
- type Color
- type ColumnW
- func (b *ColumnW) A11yLabel(s string) *T
- func (b *ColumnW) Animate(on bool) *T
- func (b *ColumnW) Colors(cs ...theme.Color) *T
- func (b *ColumnW) Format(f Formatter) *T
- func (b *ColumnW) Height(h float32) *T
- func (b *ColumnW) Key(k any) *T
- func (b *ColumnW) Label() *T
- func (b *ColumnW) Layout(o ...layout.Option) *T
- func (b *ColumnW) Legend(p LegendPos) *T
- func (b *ColumnW) Loading(on bool) *T
- func (w *ColumnW) MaxWidth(px float32) *ColumnW
- func (b *ColumnW) Mirror() *T
- func (b *ColumnW) NoTooltip() *T
- func (o *ColumnW) NoZero() *T
- func (w *ColumnW) Padding(p float64) *ColumnW
- func (w *ColumnW) Percent() *ColumnW
- func (w *ColumnW) Radius(r float32) *ColumnW
- func (o *ColumnW) Series(field string) *T
- func (w *ColumnW) Show() View
- func (w *ColumnW) Stack() *ColumnW
- func (b *ColumnW) Style(fn func(*Style)) *T
- func (o *ColumnW) X(field string) *T
- func (o *ColumnW) Y(field string) *T
- func (o *ColumnW) YMax(v float64) *T
- func (o *ColumnW) YMin(v float64) *T
- type DualW
- func (b *DualW) A11yLabel(s string) *T
- func (w *DualW) Alias(field, name string) *DualW
- func (b *DualW) Animate(on bool) *T
- func (b *DualW) Colors(cs ...theme.Color) *T
- func (w *DualW) Column(fields ...string) *DualW
- func (b *DualW) Format(f Formatter) *T
- func (b *DualW) Height(h float32) *T
- func (b *DualW) Key(k any) *T
- func (b *DualW) Label() *T
- func (b *DualW) Layout(o ...layout.Option) *T
- func (b *DualW) Legend(p LegendPos) *T
- func (w *DualW) Line(fields ...string) *DualW
- func (w *DualW) LineFormat(f Formatter) *DualW
- func (b *DualW) Loading(on bool) *T
- func (b *DualW) Mirror() *T
- func (b *DualW) NoTooltip() *T
- func (w *DualW) Show() View
- func (w *DualW) Smooth() *DualW
- func (b *DualW) Style(fn func(*Style)) *T
- func (w *DualW) X(field string) *DualW
- type Formatter
- type FunnelW
- func (b *FunnelW) A11yLabel(s string) *T
- func (b *FunnelW) Animate(on bool) *T
- func (b *FunnelW) Colors(cs ...theme.Color) *T
- func (b *FunnelW) Format(f Formatter) *T
- func (b *FunnelW) Height(h float32) *T
- func (b *FunnelW) Key(k any) *T
- func (b *FunnelW) Label() *T
- func (b *FunnelW) Layout(o ...layout.Option) *T
- func (b *FunnelW) Legend(p LegendPos) *T
- func (b *FunnelW) Loading(on bool) *T
- func (b *FunnelW) Mirror() *T
- func (w *FunnelW) NoConversion() *FunnelW
- func (b *FunnelW) NoTooltip() *T
- func (w *FunnelW) Show() View
- func (b *FunnelW) Style(fn func(*Style)) *T
- func (w *FunnelW) X(field string) *FunnelW
- func (w *FunnelW) Y(field string) *FunnelW
- type GaugeW
- func (b *GaugeW) A11yLabel(s string) *T
- func (b *GaugeW) Animate(on bool) *T
- func (w *GaugeW) Bands(stops []float64, colors ...theme.Color) *GaugeW
- func (b *GaugeW) Colors(cs ...theme.Color) *T
- func (b *GaugeW) Format(f Formatter) *T
- func (b *GaugeW) Height(h float32) *T
- func (b *GaugeW) Key(k any) *T
- func (b *GaugeW) Label() *T
- func (b *GaugeW) Layout(o ...layout.Option) *T
- func (b *GaugeW) Legend(p LegendPos) *T
- func (b *GaugeW) Loading(on bool) *T
- func (b *GaugeW) Mirror() *T
- func (b *GaugeW) NoTooltip() *T
- func (w *GaugeW) Range(lo, hi float64) *GaugeW
- func (w *GaugeW) Show() View
- func (b *GaugeW) Style(fn func(*Style)) *T
- func (w *GaugeW) Title(s string) *GaugeW
- type HeatmapW
- func (b *HeatmapW) A11yLabel(s string) *T
- func (b *HeatmapW) Animate(on bool) *T
- func (b *HeatmapW) Colors(cs ...theme.Color) *T
- func (b *HeatmapW) Format(f Formatter) *T
- func (b *HeatmapW) Height(h float32) *T
- func (b *HeatmapW) Key(k any) *T
- func (b *HeatmapW) Label() *T
- func (b *HeatmapW) Layout(o ...layout.Option) *T
- func (b *HeatmapW) Legend(p LegendPos) *T
- func (b *HeatmapW) Loading(on bool) *T
- func (b *HeatmapW) Mirror() *T
- func (b *HeatmapW) NoTooltip() *T
- func (w *HeatmapW) Ramp(cs ...Color) *HeatmapW
- func (w *HeatmapW) Show() View
- func (b *HeatmapW) Style(fn func(*Style)) *T
- func (w *HeatmapW) Value(field string) *HeatmapW
- func (w *HeatmapW) X(field string) *HeatmapW
- func (w *HeatmapW) Y(field string) *HeatmapW
- type Labels
- type LegendPos
- type LineW
- func (b *LineW) A11yLabel(s string) *T
- func (b *LineW) Animate(on bool) *T
- func (w *LineW) Area() *LineW
- func (b *LineW) Colors(cs ...theme.Color) *T
- func (b *LineW) Format(f Formatter) *T
- func (b *LineW) Height(h float32) *T
- func (b *LineW) Key(k any) *T
- func (b *LineW) Label() *T
- func (b *LineW) Layout(o ...layout.Option) *T
- func (b *LineW) Legend(p LegendPos) *T
- func (b *LineW) Loading(on bool) *T
- func (w *LineW) Log() *LineW
- func (b *LineW) Mirror() *T
- func (b *LineW) NoTooltip() *T
- func (o *LineW) NoZero() *T
- func (w *LineW) Points() *LineW
- func (o *LineW) Series(field string) *T
- func (w *LineW) Show() View
- func (w *LineW) Smooth() *LineW
- func (w *LineW) Stack() *LineW
- func (w *LineW) Step(mode ...StepMode) *LineW
- func (b *LineW) Style(fn func(*Style)) *T
- func (o *LineW) X(field string) *T
- func (o *LineW) Y(field string) *T
- func (o *LineW) YMax(v float64) *T
- func (o *LineW) YMin(v float64) *T
- type Linear
- type LiquidW
- func (b *LiquidW) A11yLabel(s string) *T
- func (b *LiquidW) Animate(on bool) *T
- func (b *LiquidW) Colors(cs ...theme.Color) *T
- func (b *LiquidW) Format(f Formatter) *T
- func (b *LiquidW) Height(h float32) *T
- func (b *LiquidW) Key(k any) *T
- func (b *LiquidW) Label() *T
- func (b *LiquidW) Layout(o ...layout.Option) *T
- func (b *LiquidW) Legend(p LegendPos) *T
- func (b *LiquidW) Loading(on bool) *T
- func (b *LiquidW) Mirror() *T
- func (b *LiquidW) NoTooltip() *T
- func (w *LiquidW) Show() View
- func (w *LiquidW) Still() *LiquidW
- func (b *LiquidW) Style(fn func(*Style)) *T
- func (w *LiquidW) Title(s string) *LiquidW
- type Log
- type Marker
- type PieW
- func (b *PieW) A11yLabel(s string) *T
- func (w *PieW) Angle(field string) *PieW
- func (b *PieW) Animate(on bool) *T
- func (w *PieW) Center(title, value string) *PieW
- func (w *PieW) Color(field string) *PieW
- func (b *PieW) Colors(cs ...theme.Color) *T
- func (b *PieW) Format(f Formatter) *T
- func (b *PieW) Height(h float32) *T
- func (w *PieW) Inner(r float64) *PieW
- func (w *PieW) InnerLabel() *PieW
- func (b *PieW) Key(k any) *T
- func (b *PieW) Label() *T
- func (b *PieW) Layout(o ...layout.Option) *T
- func (b *PieW) Legend(p LegendPos) *T
- func (b *PieW) Loading(on bool) *T
- func (b *PieW) Mirror() *T
- func (w *PieW) NoLabel() *PieW
- func (b *PieW) NoTooltip() *T
- func (w *PieW) Show() View
- func (b *PieW) Style(fn func(*Style)) *T
- type Point
- type Polar
- type RadarW
- func (b *RadarW) A11yLabel(s string) *T
- func (b *RadarW) Animate(on bool) *T
- func (w *RadarW) Circle() *RadarW
- func (b *RadarW) Colors(cs ...theme.Color) *T
- func (b *RadarW) Format(f Formatter) *T
- func (b *RadarW) Height(h float32) *T
- func (b *RadarW) Key(k any) *T
- func (b *RadarW) Label() *T
- func (b *RadarW) Layout(o ...layout.Option) *T
- func (b *RadarW) Legend(p LegendPos) *T
- func (b *RadarW) Loading(on bool) *T
- func (b *RadarW) Mirror() *T
- func (w *RadarW) NoArea() *RadarW
- func (b *RadarW) NoTooltip() *T
- func (o *RadarW) NoZero() *T
- func (o *RadarW) Series(field string) *T
- func (w *RadarW) Show() View
- func (b *RadarW) Style(fn func(*Style)) *T
- func (o *RadarW) X(field string) *T
- func (o *RadarW) Y(field string) *T
- func (o *RadarW) YMax(v float64) *T
- func (o *RadarW) YMin(v float64) *T
- type Row
- type ScatterW
- func (b *ScatterW) A11yLabel(s string) *T
- func (b *ScatterW) Animate(on bool) *T
- func (b *ScatterW) Colors(cs ...theme.Color) *T
- func (b *ScatterW) Format(f Formatter) *T
- func (b *ScatterW) Height(h float32) *T
- func (b *ScatterW) Key(k any) *T
- func (b *ScatterW) Label() *T
- func (b *ScatterW) Layout(o ...layout.Option) *T
- func (b *ScatterW) Legend(p LegendPos) *T
- func (b *ScatterW) Loading(on bool) *T
- func (b *ScatterW) Mirror() *T
- func (b *ScatterW) NoTooltip() *T
- func (o *ScatterW) NoZero() *T
- func (w *ScatterW) Radius(min, max float32) *ScatterW
- func (o *ScatterW) Series(field string) *T
- func (w *ScatterW) Show() View
- func (w *ScatterW) Size(field string) *ScatterW
- func (b *ScatterW) Style(fn func(*Style)) *T
- func (o *ScatterW) X(field string) *T
- func (w *ScatterW) XFormat(f Formatter) *ScatterW
- func (o *ScatterW) Y(field string) *T
- func (o *ScatterW) YMax(v float64) *T
- func (o *ScatterW) YMin(v float64) *T
- func (w *ScatterW) Zero() *ScatterW
- type StepMode
- type Style
- type StyleFunc
- type TimeScale
- type TimeTick
- type TimeUnit
- type TinyW
- func (b *TinyW) A11yLabel(s string) *T
- func (b *TinyW) Animate(on bool) *T
- func (w *TinyW) Color(col theme.Color) *TinyW
- func (b *TinyW) Colors(cs ...theme.Color) *T
- func (b *TinyW) Format(f Formatter) *T
- func (b *TinyW) Height(h float32) *T
- func (b *TinyW) Key(k any) *T
- func (b *TinyW) Label() *T
- func (b *TinyW) Layout(o ...layout.Option) *T
- func (b *TinyW) Legend(p LegendPos) *T
- func (b *TinyW) Loading(on bool) *T
- func (b *TinyW) Mirror() *T
- func (w *TinyW) Names(names ...string) *TinyW
- func (b *TinyW) NoTooltip() *T
- func (w *TinyW) Show() View
- func (w *TinyW) Smooth() *TinyW
- func (b *TinyW) Style(fn func(*Style)) *T
- func (w *TinyW) Target(v float64) *TinyW
- type Tip
- type TipItem
- type View
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DataTable ¶
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 ¶
FormatCompact abbreviates large values: 万 / 亿 for Chinese locales ("zh-CN"), K / M / B otherwise. Values below the first unit keep thousands separators.
func FormatNumber ¶
FormatNumber formats v with thousands separators and the given number of decimals (negative: shortest exact representation).
func LTTB ¶
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 ¶
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 ¶
NiceStep returns a round tick step (1, 2 or 5 × 10^k) that divides span into about count intervals.
func Num ¶
Num converts a field value to float64. Strings are not parsed: a string is a category, not a number.
func RegisterStyle ¶
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 ¶
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.
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).
type Cartesian ¶
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).
type ColumnW ¶
type ColumnW struct {
// contains filtered or unexported fields
}
ColumnW builds a column (vertical) or bar (horizontal) chart.
func Bar ¶
Bar starts a horizontal bar chart: X is the category field (listed top to bottom), Y the value.
func Column ¶
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) 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) 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) 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) Series ¶
func (o *ColumnW) Series(field string) *T
Series sets the field that splits rows into series (legend, colors).
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.
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 ¶
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) Animate ¶
func (b *DualW) Animate(on bool) *T
Animate enables (default) or disables entry and update transitions.
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) Legend ¶
func (b *DualW) Legend(p LegendPos) *T
Legend places (or with LegendNone hides) the legend.
func (*DualW) LineFormat ¶
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.
type Formatter ¶
Formatter turns a value into a label.
type FunnelW ¶
type FunnelW struct {
// contains filtered or unexported fields
}
FunnelW builds a funnel chart.
func Funnel ¶
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) 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) 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 ¶
NoConversion hides the stage-to-stage conversion rates.
func (*FunnelW) NoTooltip ¶
func (b *FunnelW) NoTooltip() *T
NoTooltip disables the hover tooltip and crosshair.
type GaugeW ¶
type GaugeW struct {
// contains filtered or unexported fields
}
GaugeW builds a gauge (dial) chart.
func Gauge ¶
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 ¶
Bands colors the track by thresholds (upper bounds in scale units, sorted) instead of a single progress arc.
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) 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.
type HeatmapW ¶
type HeatmapW struct {
// contains filtered or unexported fields
}
HeatmapW builds a heatmap over two category fields.
func Heatmap ¶
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) 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) 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) Style ¶
func (b *HeatmapW) Style(fn func(*Style)) *T
Style tweaks the resolved chart style for this chart only.
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.
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 Line ¶
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) 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) 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) 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) Series ¶
func (o *LineW) Series(field string) *T
Series sets the field that splits rows into series (legend, colors).
type Linear ¶
Linear maps the domain [D0, D1] onto the range [R0, R1].
type LiquidW ¶
type LiquidW struct {
// contains filtered or unexported fields
}
LiquidW builds a liquid fill (water wave) gauge.
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) 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) 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.
type Log ¶
Log maps a positive domain logarithmically onto the range.
type PieW ¶
type PieW struct {
// contains filtered or unexported fields
}
PieW builds a pie or donut chart.
func Pie ¶
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) Animate ¶
func (b *PieW) Animate(on bool) *T
Animate enables (default) or disables entry and update transitions.
func (*PieW) Center ¶
Center sets the donut centre statistic (default: total of the visible slices; empty strings hide it).
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) InnerLabel ¶
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) 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.
type Point ¶
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.
type Polar ¶
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 (Polar) Locate ¶
Locate inverts At: t in [0,1) for full circles, and the pixel distance from the centre.
type RadarW ¶
type RadarW struct {
// contains filtered or unexported fields
}
RadarW builds a radar (spider) chart.
func Radar ¶
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) 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) 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) 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) 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.
type Row ¶
Row is one datum: field name to value. Values may be any Go number, string (category), time.Time, or nil (missing).
type ScatterW ¶
type ScatterW struct {
// contains filtered or unexported fields
}
ScatterW builds a scatter or bubble chart.
func Scatter ¶
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) 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) 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) Series ¶
func (o *ScatterW) Series(field string) *T
Series sets the field that splits rows into series (legend, colors).
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) YMax ¶
func (o *ScatterW) YMax(v float64) *T
YMax fixes the upper end of the value axis.
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 EChartsStyle ¶
EChartsStyle is the ECharts 5 default look, used for Element Plus.
func ShadcnStyle ¶
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.
type TimeScale ¶
TimeScale maps a time domain onto the range.
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.
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 TinyColumn ¶
TinyColumn starts a mini column chart.
func TinyProgress ¶
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) 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) 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) NoTooltip ¶
func (b *TinyW) NoTooltip() *T
NoTooltip disables the hover tooltip and crosshair.