chart 实验性
实验性
本包属于实验层:任何 0.x 版本都可能有不兼容变化(docs/release.md「API 稳定性」)。
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
func DataTable(c *ui.Context, rows []Row, fields ...string) *ui.TableWDataTable builds a ui.Table of rows with one column per field (titled by the field name): the accessible alternative of a chart, for apps that offer a "view as table" toggle next to it.
if showTable {
chart.DataTable(c, rows, "month", "city", "temp").Show()
} else {
chart.Line(c, rows).X("month").Y("temp").Series("city").Show()
}
func FormatCompact
func FormatCompact(v float64, locale string) stringFormatCompact abbreviates large values: 万 / 亿 for Chinese locales ("zh-CN"), K / M / B otherwise. Values below the first unit keep thousands separators.
func FormatNumber
func FormatNumber(v float64, decimals int) stringFormatNumber formats v with thousands separators and the given number of decimals (negative: shortest exact representation).
func LTTB
func LTTB(xs, ys []float64, threshold int) []intLTTB downsamples the series (xs[i], ys[i]) to at most threshold points with the Largest-Triangle-Three-Buckets algorithm (Steinarsson, 2013, "Downsampling Time Series for Visual Representation"). It returns the indices of the kept points in ascending order; the first and last points are always kept. NaN y values are skipped. With threshold < 3 or fewer points than threshold, every valid index is returned.
func NiceDomain
func NiceDomain(lo, hi float64, count int) (nlo, nhi, step float64)NiceDomain extends [lo, hi] outward to multiples of a nice step with about count ticks. A zero span is widened around the value (0 becomes [0, 1]); NaN or infinite input yields [0, 1].
func NiceStep
func NiceStep(span float64, count int) float64NiceStep returns a round tick step (1, 2 or 5 × 10^k) that divides span into about count intervals.
func NiceTicks
func NiceTicks(lo, hi float64, count int) []float64NiceTicks returns the nice domain and its ticks for data in [lo, hi].
func Num
func Num(v any) (float64, bool)Num converts a field value to float64. Strings are not parsed: a string is a category, not a number.
func RegisterStyle
func RegisterStyle(match func(*theme.Theme) bool, fn StyleFunc)RegisterStyle installs a chart style for themes accepted by match; later registrations take precedence. Built-in styles: Ant (G2 classic) for theme.Ant and ECharts for theme.Element, each with a dark variant.
chart.RegisterStyle(func(t *theme.Theme) bool { return t.Name == "shadcn" },
func(t *theme.Theme) *chart.Style {
s := chart.AntStyle(t)
s.Colors = shadcnPalette
return s
})
func Stack
func Stack(vals [][]float64, hidden []bool, percent bool) (lo, hi [][]float64)Stack stacks series values per x position. vals[s][i] is the value of series s at x i (NaN = missing, treated as 0); hidden series contribute nothing. Positive values stack upward from 0 and negative values downward, so mixed signs never overlap. With percent each column is normalised so the absolute values sum to 1 (positives to the share above 0, negatives below). It returns the lower and upper bound of every segment.
func Str
func Str(v any) stringStr converts a field value to its category label.
func TimeOf
func TimeOf(v any) (time.Time, bool)TimeOf converts a field value to a time.
类型
Band
type Band struct {
N int
R0, R1 float64
PaddingInner float64 // fraction of the step left empty between bands
PaddingOuter float64 // fraction of the step before the first / after the last band
}Band divides the range into equal bands, one per category (bars).
func (Band) Bandwidth
func (s Band) Bandwidth() float64Bandwidth returns the width of one band.
func (Band) Center
func (s Band) Center(i int) float64Center returns the middle of band i.
func (Band) Index
func (s Band) Index(p float64) intIndex returns the band whose step contains p (-1 outside).
func (Band) Map
func (s Band) Map(i int) float64Map returns the start of band i.
func (Band) Step
func (s Band) Step() float64Step returns the distance between band starts.
Cartesian
type Cartesian struct {
Plot geom.Rect
Transposed bool
Mirror bool
}Cartesian maps normalised coordinates (0..1, y up) into a plot rect. Transposed swaps the axes: x runs top to bottom and y left to right (horizontal bars). Mirror reverses the horizontal pixel axis: it runs right to left (x for columns, y for horizontal bars).
func (Cartesian) At
func (c Cartesian) At(nx, ny float64) geom.PointAt returns the pixel position of normalised (nx, ny).
func (Cartesian) HX
func (c Cartesian) HX(t float64) float32HX returns the pixel x of normalised position t on the horizontal pixel axis (x, or y when transposed).
func (Cartesian) Norm
func (c Cartesian) Norm(pt geom.Point) (nx, ny float64)Norm inverts At.
func (Cartesian) Rect
func (c Cartesian) Rect(x0, x1, y0, y1 float64) geom.RectRect returns the pixel rect spanning normalised x0..x1 and y0..y1.
Color
type Color = theme.ColorColor is a theme color (ramps, overrides).
ColumnW
type ColumnW struct {
// contains filtered or unexported fields
}ColumnW builds a column (vertical) or bar (horizontal) chart.
func Bar
func Bar(c *ui.Context, data []Row) *ColumnWBar starts a horizontal bar chart: X is the category field (listed top to bottom), Y the value.
func Column
func Column(c *ui.Context, data []Row) *ColumnWColumn 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) *TA11yLabel 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) *TAnimate enables (default) or disables entry and update transitions.
func (*ColumnW) Colors
func (b *ColumnW) Colors(cs ...theme.Color) *TColors overrides the palette.
func (*ColumnW) Format
func (b *ColumnW) Format(f Formatter) *TFormat sets the value formatter used by the value axis, tooltip and labels (default: thousands separators).
func (*ColumnW) Height
func (b *ColumnW) Height(h float32) *THeight sets the chart height in logical pixels (the width follows the parent).
func (*ColumnW) Key
func (b *ColumnW) Key(k any) *TKey gives the chart a stable identity (legend and animation state) when charts are added or removed around it.
func (*ColumnW) Label
func (b *ColumnW) Label() *TLabel shows data labels on the marks.
func (*ColumnW) Layout
func (b *ColumnW) Layout(o ...layout.Option) *TLayout applies layout options to the chart box (Grow, Margin ...).
func (*ColumnW) Legend
func (b *ColumnW) Legend(p LegendPos) *TLegend places (or with LegendNone hides) the legend.
func (*ColumnW) Loading
func (b *ColumnW) Loading(on bool) *TLoading shows a spinner over the chart (or in place of it without data).
func (*ColumnW) MaxWidth
func (w *ColumnW) MaxWidth(px float32) *ColumnWMaxWidth caps the bar thickness.
func (*ColumnW) Mirror
func (b *ColumnW) Mirror() *TMirror 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() *TNoTooltip disables the hover tooltip and crosshair.
func (*ColumnW) NoZero
func (o *ColumnW) NoZero() *TNoZero lets the value axis start near the data instead of at zero.
func (*ColumnW) Padding
func (w *ColumnW) Padding(p float64) *ColumnWPadding sets the empty fraction between bands (0..1).
func (*ColumnW) Percent
func (w *ColumnW) Percent() *ColumnWPercent stacks the series normalised to 100%.
func (*ColumnW) Radius
func (w *ColumnW) Radius(r float32) *ColumnWRadius rounds the bar ends.
func (*ColumnW) Series
func (o *ColumnW) Series(field string) *TSeries sets the field that splits rows into series (legend, colors).
func (*ColumnW) Show
func (w *ColumnW) Show() ViewShow builds the chart.
func (*ColumnW) Stack
func (w *ColumnW) Stack() *ColumnWStack stacks the series.
func (*ColumnW) Style
func (b *ColumnW) Style(fn func(*Style)) *TStyle tweaks the resolved chart style for this chart only.
func (*ColumnW) X
func (o *ColumnW) X(field string) *TX sets the x (category / time / number) field.
func (*ColumnW) Y
func (o *ColumnW) Y(field string) *TY sets the value field.
func (*ColumnW) YMax
func (o *ColumnW) YMax(v float64) *TYMax fixes the upper end of the value axis.
func (*ColumnW) YMin
func (o *ColumnW) YMin(v float64) *TYMin fixes the lower end of the value axis.
DualW
type DualW struct {
// contains filtered or unexported fields
}DualW builds a dual-axes chart: columns on the left axis, lines on the right axis, over a shared category x.
func DualAxes
func DualAxes(c *ui.Context, data []Row) *DualWDualAxes 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) *TA11yLabel sets the accessible name of the chart (default: its title or the localized chart kind, e.g. "折线图").
func (*DualW) Alias
func (w *DualW) Alias(field, name string) *DualWAlias sets the legend / tooltip name of a field.
func (*DualW) Animate
func (b *DualW) Animate(on bool) *TAnimate enables (default) or disables entry and update transitions.
func (*DualW) Colors
func (b *DualW) Colors(cs ...theme.Color) *TColors overrides the palette.
func (*DualW) Column
func (w *DualW) Column(fields ...string) *DualWColumn adds fields drawn as grouped columns on the left axis.
func (*DualW) Format
func (b *DualW) Format(f Formatter) *TFormat sets the value formatter used by the value axis, tooltip and labels (default: thousands separators).
func (*DualW) Height
func (b *DualW) Height(h float32) *THeight sets the chart height in logical pixels (the width follows the parent).
func (*DualW) Key
func (b *DualW) Key(k any) *TKey gives the chart a stable identity (legend and animation state) when charts are added or removed around it.
func (*DualW) Label
func (b *DualW) Label() *TLabel shows data labels on the marks.
func (*DualW) Layout
func (b *DualW) Layout(o ...layout.Option) *TLayout applies layout options to the chart box (Grow, Margin ...).
func (*DualW) Legend
func (b *DualW) Legend(p LegendPos) *TLegend places (or with LegendNone hides) the legend.
func (*DualW) Line
func (w *DualW) Line(fields ...string) *DualWLine adds fields drawn as lines on the right axis.
func (*DualW) LineFormat
func (w *DualW) LineFormat(f Formatter) *DualWLineFormat formats the right axis and line values.
func (*DualW) Loading
func (b *DualW) Loading(on bool) *TLoading shows a spinner over the chart (or in place of it without data).
func (*DualW) Mirror
func (b *DualW) Mirror() *TMirror 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() *TNoTooltip disables the hover tooltip and crosshair.
func (*DualW) Show
func (w *DualW) Show() ViewShow builds the chart.
func (*DualW) Smooth
func (w *DualW) Smooth() *DualWSmooth draws the lines as monotone curves.
func (*DualW) Style
func (b *DualW) Style(fn func(*Style)) *TStyle tweaks the resolved chart style for this chart only.
func (*DualW) X
func (w *DualW) X(field string) *DualWX sets the category field.
Formatter
type Formatter func(v float64) stringFormatter turns a value into a label.
func Compact
func Compact(locale string) FormatterCompact returns FormatCompact bound to a locale code (c.Locale().Code).
func Percent
func Percent(decimals int) FormatterPercent formats a ratio (0.256 → "25.6%").
func Thousands
func Thousands(decimals int) FormatterThousands returns a formatter with thousands separators.
func Unit
func Unit(unit string, decimals int) FormatterUnit appends a unit suffix to a thousands-separated value.
FunnelW
type FunnelW struct {
// contains filtered or unexported fields
}FunnelW builds a funnel chart.
func Funnel
func Funnel(c *ui.Context, data []Row) *FunnelWFunnel 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) *TA11yLabel 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) *TAnimate enables (default) or disables entry and update transitions.
func (*FunnelW) Colors
func (b *FunnelW) Colors(cs ...theme.Color) *TColors overrides the palette.
func (*FunnelW) Format
func (b *FunnelW) Format(f Formatter) *TFormat sets the value formatter used by the value axis, tooltip and labels (default: thousands separators).
func (*FunnelW) Height
func (b *FunnelW) Height(h float32) *THeight sets the chart height in logical pixels (the width follows the parent).
func (*FunnelW) Key
func (b *FunnelW) Key(k any) *TKey gives the chart a stable identity (legend and animation state) when charts are added or removed around it.
func (*FunnelW) Label
func (b *FunnelW) Label() *TLabel shows data labels on the marks.
func (*FunnelW) Layout
func (b *FunnelW) Layout(o ...layout.Option) *TLayout applies layout options to the chart box (Grow, Margin ...).
func (*FunnelW) Legend
func (b *FunnelW) Legend(p LegendPos) *TLegend places (or with LegendNone hides) the legend.
func (*FunnelW) Loading
func (b *FunnelW) Loading(on bool) *TLoading shows a spinner over the chart (or in place of it without data).
func (*FunnelW) Mirror
func (b *FunnelW) Mirror() *TMirror draws the plot right to left: the x axis runs from the right, the value axis sits on the right, bars, lines, areas and points are mirrored (so categories read in reverse order), and pie, donut, radar and gauge start at the mirrored angle and sweep counter-clockwise. Labels stay readable; only their positions move. Without it the plot is drawn left to right even in RTL scopes, while the legend, tooltip and labels follow the scope direction.
func (*FunnelW) NoConversion
func (w *FunnelW) NoConversion() *FunnelWNoConversion hides the stage-to-stage conversion rates.
func (*FunnelW) NoTooltip
func (b *FunnelW) NoTooltip() *TNoTooltip disables the hover tooltip and crosshair.
func (*FunnelW) Show
func (w *FunnelW) Show() ViewShow builds the chart.
func (*FunnelW) Style
func (b *FunnelW) Style(fn func(*Style)) *TStyle tweaks the resolved chart style for this chart only.
func (*FunnelW) X
func (w *FunnelW) X(field string) *FunnelWX sets the stage field.
func (*FunnelW) Y
func (w *FunnelW) Y(field string) *FunnelWY sets the value field.
GaugeW
type GaugeW struct {
// contains filtered or unexported fields
}GaugeW builds a gauge (dial) chart.
func Gauge
func Gauge(c *ui.Context, value float64) *GaugeWGauge 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) *TA11yLabel 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) *TAnimate enables (default) or disables entry and update transitions.
func (*GaugeW) Bands
func (w *GaugeW) Bands(stops []float64, colors ...theme.Color) *GaugeWBands colors the track by thresholds (upper bounds in scale units, sorted) instead of a single progress arc.
func (*GaugeW) Colors
func (b *GaugeW) Colors(cs ...theme.Color) *TColors overrides the palette.
func (*GaugeW) Format
func (b *GaugeW) Format(f Formatter) *TFormat sets the value formatter used by the value axis, tooltip and labels (default: thousands separators).
func (*GaugeW) Height
func (b *GaugeW) Height(h float32) *THeight sets the chart height in logical pixels (the width follows the parent).
func (*GaugeW) Key
func (b *GaugeW) Key(k any) *TKey gives the chart a stable identity (legend and animation state) when charts are added or removed around it.
func (*GaugeW) Label
func (b *GaugeW) Label() *TLabel shows data labels on the marks.
func (*GaugeW) Layout
func (b *GaugeW) Layout(o ...layout.Option) *TLayout applies layout options to the chart box (Grow, Margin ...).
func (*GaugeW) Legend
func (b *GaugeW) Legend(p LegendPos) *TLegend places (or with LegendNone hides) the legend.
func (*GaugeW) Loading
func (b *GaugeW) Loading(on bool) *TLoading shows a spinner over the chart (or in place of it without data).
func (*GaugeW) Mirror
func (b *GaugeW) Mirror() *TMirror 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() *TNoTooltip disables the hover tooltip and crosshair.
func (*GaugeW) Range
func (w *GaugeW) Range(lo, hi float64) *GaugeWRange sets the scale bounds (default 0..1, shown as percentages).
func (*GaugeW) Show
func (w *GaugeW) Show() ViewShow builds the chart.
func (*GaugeW) Style
func (b *GaugeW) Style(fn func(*Style)) *TStyle tweaks the resolved chart style for this chart only.
func (*GaugeW) Title
func (w *GaugeW) Title(s string) *GaugeWTitle sets the caption under the value.
HeatmapW
type HeatmapW struct {
// contains filtered or unexported fields
}HeatmapW builds a heatmap over two category fields.
func Heatmap
func Heatmap(c *ui.Context, data []Row) *HeatmapWHeatmap 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) *TA11yLabel 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) *TAnimate enables (default) or disables entry and update transitions.
func (*HeatmapW) Colors
func (b *HeatmapW) Colors(cs ...theme.Color) *TColors overrides the palette.
func (*HeatmapW) Format
func (b *HeatmapW) Format(f Formatter) *TFormat sets the value formatter used by the value axis, tooltip and labels (default: thousands separators).
func (*HeatmapW) Height
func (b *HeatmapW) Height(h float32) *THeight sets the chart height in logical pixels (the width follows the parent).
func (*HeatmapW) Key
func (b *HeatmapW) Key(k any) *TKey gives the chart a stable identity (legend and animation state) when charts are added or removed around it.
func (*HeatmapW) Label
func (b *HeatmapW) Label() *TLabel shows data labels on the marks.
func (*HeatmapW) Layout
func (b *HeatmapW) Layout(o ...layout.Option) *TLayout applies layout options to the chart box (Grow, Margin ...).
func (*HeatmapW) Legend
func (b *HeatmapW) Legend(p LegendPos) *TLegend places (or with LegendNone hides) the legend.
func (*HeatmapW) Loading
func (b *HeatmapW) Loading(on bool) *TLoading shows a spinner over the chart (or in place of it without data).
func (*HeatmapW) Mirror
func (b *HeatmapW) Mirror() *TMirror 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() *TNoTooltip disables the hover tooltip and crosshair.
func (*HeatmapW) Ramp
func (w *HeatmapW) Ramp(cs ...Color) *HeatmapWRamp overrides the sequential palette (low → high).
func (*HeatmapW) Show
func (w *HeatmapW) Show() ViewShow builds the chart.
func (*HeatmapW) Style
func (b *HeatmapW) Style(fn func(*Style)) *TStyle tweaks the resolved chart style for this chart only.
func (*HeatmapW) Value
func (w *HeatmapW) Value(field string) *HeatmapWValue sets the numeric field mapped to color.
func (*HeatmapW) X
func (w *HeatmapW) X(field string) *HeatmapWX sets the column category field.
func (*HeatmapW) Y
func (w *HeatmapW) Y(field string) *HeatmapWY sets the row category field (first category on top).
Labels
type Labels struct {
Year func(y int) string // "2026年" / "2026"
Month func(m int) string // "2月" / "Feb"
}Labels formats the calendar parts of time tick labels.
func LabelsOf
func LabelsOf(l *ui.Locale) LabelsLabelsOf takes the time label texts from a ui locale.
LegendPos
type LegendPos uint8LegendPos 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
)LineW
type LineW struct {
// contains filtered or unexported fields
}LineW builds a line or area chart.
func Area
func Area(c *ui.Context, data []Row) *LineWArea starts an area chart (a line chart with the area filled).
func Line
func Line(c *ui.Context, data []Row) *LineWLine 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) *TA11yLabel 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) *TAnimate enables (default) or disables entry and update transitions.
func (*LineW) Area
func (w *LineW) Area() *LineWArea fills the area below each line.
func (*LineW) Colors
func (b *LineW) Colors(cs ...theme.Color) *TColors overrides the palette.
func (*LineW) Format
func (b *LineW) Format(f Formatter) *TFormat sets the value formatter used by the value axis, tooltip and labels (default: thousands separators).
func (*LineW) Height
func (b *LineW) Height(h float32) *THeight sets the chart height in logical pixels (the width follows the parent).
func (*LineW) Key
func (b *LineW) Key(k any) *TKey gives the chart a stable identity (legend and animation state) when charts are added or removed around it.
func (*LineW) Label
func (b *LineW) Label() *TLabel shows data labels on the marks.
func (*LineW) Layout
func (b *LineW) Layout(o ...layout.Option) *TLayout applies layout options to the chart box (Grow, Margin ...).
func (*LineW) Legend
func (b *LineW) Legend(p LegendPos) *TLegend places (or with LegendNone hides) the legend.
func (*LineW) Loading
func (b *LineW) Loading(on bool) *TLoading shows a spinner over the chart (or in place of it without data).
func (*LineW) Log
func (w *LineW) Log() *LineWLog uses a logarithmic value axis.
func (*LineW) Mirror
func (b *LineW) Mirror() *TMirror 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() *TNoTooltip disables the hover tooltip and crosshair.
func (*LineW) NoZero
func (o *LineW) NoZero() *TNoZero lets the value axis start near the data instead of at zero.
func (*LineW) Points
func (w *LineW) Points() *LineWPoints draws a symbol at every data point.
func (*LineW) Series
func (o *LineW) Series(field string) *TSeries sets the field that splits rows into series (legend, colors).
func (*LineW) Show
func (w *LineW) Show() ViewShow builds the chart.
func (*LineW) Smooth
func (w *LineW) Smooth() *LineWSmooth draws monotone curves instead of straight segments.
func (*LineW) Stack
func (w *LineW) Stack() *LineWStack stacks the series (stacked area when combined with Area).
func (*LineW) Step
func (w *LineW) Step(mode ...StepMode) *LineWStep draws a step line (default StepEnd: horizontal, then vertical).
func (*LineW) Style
func (b *LineW) Style(fn func(*Style)) *TStyle tweaks the resolved chart style for this chart only.
func (*LineW) X
func (o *LineW) X(field string) *TX sets the x (category / time / number) field.
func (*LineW) Y
func (o *LineW) Y(field string) *TY sets the value field.
func (*LineW) YMax
func (o *LineW) YMax(v float64) *TYMax fixes the upper end of the value axis.
func (*LineW) YMin
func (o *LineW) YMin(v float64) *TYMin fixes the lower end of the value axis.
Linear
type Linear struct {
D0, D1 float64
R0, R1 float64
}Linear maps the domain [D0, D1] onto the range [R0, R1].
func (Linear) Invert
func (s Linear) Invert(p float64) float64Invert returns the domain value at range position p.
func (Linear) Map
func (s Linear) Map(v float64) float64Map returns the range position of v.
func (*Linear) Nice
func (s *Linear) Nice(count int) float64Nice extends the domain outward to nice round values and returns the tick step.
func (Linear) Ticks
func (s Linear) Ticks(count int) []float64Ticks returns about count nice tick values inside the domain.
LiquidW
type LiquidW struct {
// contains filtered or unexported fields
}LiquidW builds a liquid fill (water wave) gauge.
func Liquid
func Liquid(c *ui.Context, ratio float64) *LiquidWLiquid starts a water wave gauge at ratio 0..1.
func (*LiquidW) A11yLabel
func (b *LiquidW) A11yLabel(s string) *TA11yLabel 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) *TAnimate enables (default) or disables entry and update transitions.
func (*LiquidW) Colors
func (b *LiquidW) Colors(cs ...theme.Color) *TColors overrides the palette.
func (*LiquidW) Format
func (b *LiquidW) Format(f Formatter) *TFormat sets the value formatter used by the value axis, tooltip and labels (default: thousands separators).
func (*LiquidW) Height
func (b *LiquidW) Height(h float32) *THeight sets the chart height in logical pixels (the width follows the parent).
func (*LiquidW) Key
func (b *LiquidW) Key(k any) *TKey gives the chart a stable identity (legend and animation state) when charts are added or removed around it.
func (*LiquidW) Label
func (b *LiquidW) Label() *TLabel shows data labels on the marks.
func (*LiquidW) Layout
func (b *LiquidW) Layout(o ...layout.Option) *TLayout applies layout options to the chart box (Grow, Margin ...).
func (*LiquidW) Legend
func (b *LiquidW) Legend(p LegendPos) *TLegend places (or with LegendNone hides) the legend.
func (*LiquidW) Loading
func (b *LiquidW) Loading(on bool) *TLoading shows a spinner over the chart (or in place of it without data).
func (*LiquidW) Mirror
func (b *LiquidW) Mirror() *TMirror 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() *TNoTooltip disables the hover tooltip and crosshair.
func (*LiquidW) Show
func (w *LiquidW) Show() ViewShow builds the chart.
func (*LiquidW) Still
func (w *LiquidW) Still() *LiquidWStill stops the wave motion (static screenshots, reduced motion).
func (*LiquidW) Style
func (b *LiquidW) Style(fn func(*Style)) *TStyle tweaks the resolved chart style for this chart only.
func (*LiquidW) Title
func (w *LiquidW) Title(s string) *LiquidWTitle sets the caption under the percentage.
Log
type Log struct {
D0, D1 float64 // > 0
R0, R1 float64
Base float64 // 0 means 10
}Log maps a positive domain logarithmically onto the range.
func (Log) Map
func (s Log) Map(v float64) float64Map returns the range position of v (values <= 0 clamp to the low end).
func (*Log) Nice
func (s *Log) Nice()Nice extends the domain to whole powers of the base.
func (Log) Ticks
func (s Log) Ticks() []float64Ticks returns the powers of the base inside the domain (and 2×, 5× steps when the domain spans fewer than three decades).
Marker
type Marker uint8Marker is a legend / tooltip marker shape.
const (
MarkerCircle Marker = iota // dot (G2)
MarkerRoundRect // 25×14 rounded rect (ECharts)
MarkerLine // line with a hollow dot (ECharts line series)
MarkerSquare
)PieW
type PieW struct {
// contains filtered or unexported fields
}PieW builds a pie or donut chart.
func Donut
func Donut(c *ui.Context, data []Row) *PieWDonut starts a donut (ring) chart with a centre statistic.
func Pie
func Pie(c *ui.Context, data []Row) *PieWPie 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) *TA11yLabel sets the accessible name of the chart (default: its title or the localized chart kind, e.g. "折线图").
func (*PieW) Angle
func (w *PieW) Angle(field string) *PieWAngle sets the value field.
func (*PieW) Animate
func (b *PieW) Animate(on bool) *TAnimate enables (default) or disables entry and update transitions.
func (*PieW) Center
func (w *PieW) Center(title, value string) *PieWCenter sets the donut centre statistic (default: total of the visible slices; empty strings hide it).
func (*PieW) Color
func (w *PieW) Color(field string) *PieWColor sets the slice name field.
func (*PieW) Colors
func (b *PieW) Colors(cs ...theme.Color) *TColors overrides the palette.
func (*PieW) Format
func (b *PieW) Format(f Formatter) *TFormat sets the value formatter used by the value axis, tooltip and labels (default: thousands separators).
func (*PieW) Height
func (b *PieW) Height(h float32) *THeight sets the chart height in logical pixels (the width follows the parent).
func (*PieW) Inner
func (w *PieW) Inner(r float64) *PieWInner sets the hole radius as a fraction of the outer radius (donut).
func (*PieW) InnerLabel
func (w *PieW) InnerLabel() *PieWInnerLabel draws percentages inside the slices instead of outer labels.
func (*PieW) Key
func (b *PieW) Key(k any) *TKey gives the chart a stable identity (legend and animation state) when charts are added or removed around it.
func (*PieW) Label
func (b *PieW) Label() *TLabel shows data labels on the marks.
func (*PieW) Layout
func (b *PieW) Layout(o ...layout.Option) *TLayout applies layout options to the chart box (Grow, Margin ...).
func (*PieW) Legend
func (b *PieW) Legend(p LegendPos) *TLegend places (or with LegendNone hides) the legend.
func (*PieW) Loading
func (b *PieW) Loading(on bool) *TLoading shows a spinner over the chart (or in place of it without data).
func (*PieW) Mirror
func (b *PieW) Mirror() *TMirror draws the plot right to left: the x axis runs from the right, the value axis sits on the right, bars, lines, areas and points are mirrored (so categories read in reverse order), and pie, donut, radar and gauge start at the mirrored angle and sweep counter-clockwise. Labels stay readable; only their positions move. Without it the plot is drawn left to right even in RTL scopes, while the legend, tooltip and labels follow the scope direction.
func (*PieW) NoLabel
func (w *PieW) NoLabel() *PieWNoLabel hides the outer labels and their leader lines.
func (*PieW) NoTooltip
func (b *PieW) NoTooltip() *TNoTooltip disables the hover tooltip and crosshair.
func (*PieW) Show
func (w *PieW) Show() ViewShow builds the chart.
func (*PieW) Style
func (b *PieW) Style(fn func(*Style)) *TStyle tweaks the resolved chart style for this chart only.
Point
type Point struct {
N int
R0, R1 float64
Padding float64
}Point places categories at evenly spaced points (lines over categories). Padding is the fraction of a step left before the first and after the last point: 0 puts them on the edges, 0.5 on band centres.
func (Point) Index
func (s Point) Index(p float64) intIndex returns the point nearest to p.
func (Point) Map
func (s Point) Map(i int) float64Map returns the position of point i.
Polar
type Polar struct {
Center geom.Point
Inner, Outer float32
Start, Sweep float64
}Polar maps (t, r) — t the fraction of the sweep, r the fraction between Inner and Outer — to pixels. Start is the angle of t = 0 in radians (y-down, so -π/2 is 12 o'clock) and Sweep the total angle (2π clockwise for a full circle).
func NewPolar
func NewPolar(r geom.Rect, inner float64) PolarNewPolar centres a full clockwise circle starting at 12 o'clock in r.
func (Polar) Angle
func (p Polar) Angle(t float64) float64Angle returns the angle of t.
func (Polar) At
func (p Polar) At(t, r float64) geom.PointAt returns the pixel position of (t, r).
func (Polar) Locate
func (p Polar) Locate(pt geom.Point) (t float64, dist float32)Locate inverts At: t in [0,1) for full circles, and the pixel distance from the centre.
func (Polar) Mirrored
func (p Polar) Mirrored() PolarMirrored returns p reflected about the vertical line through its centre: the start angle is mirrored (θ → π − θ) and the sweep reversed, so a clockwise chart becomes counter-clockwise.
func (Polar) Radius
func (p Polar) Radius(r float64) float32Radius returns the pixel radius of r.
RadarW
type RadarW struct {
// contains filtered or unexported fields
}RadarW builds a radar (spider) chart.
func Radar
func Radar(c *ui.Context, data []Row) *RadarWRadar 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) *TA11yLabel 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) *TAnimate enables (default) or disables entry and update transitions.
func (*RadarW) Circle
func (w *RadarW) Circle() *RadarWCircle draws a circular grid instead of polygons.
func (*RadarW) Colors
func (b *RadarW) Colors(cs ...theme.Color) *TColors overrides the palette.
func (*RadarW) Format
func (b *RadarW) Format(f Formatter) *TFormat sets the value formatter used by the value axis, tooltip and labels (default: thousands separators).
func (*RadarW) Height
func (b *RadarW) Height(h float32) *THeight sets the chart height in logical pixels (the width follows the parent).
func (*RadarW) Key
func (b *RadarW) Key(k any) *TKey gives the chart a stable identity (legend and animation state) when charts are added or removed around it.
func (*RadarW) Label
func (b *RadarW) Label() *TLabel shows data labels on the marks.
func (*RadarW) Layout
func (b *RadarW) Layout(o ...layout.Option) *TLayout applies layout options to the chart box (Grow, Margin ...).
func (*RadarW) Legend
func (b *RadarW) Legend(p LegendPos) *TLegend places (or with LegendNone hides) the legend.
func (*RadarW) Loading
func (b *RadarW) Loading(on bool) *TLoading shows a spinner over the chart (or in place of it without data).
func (*RadarW) Mirror
func (b *RadarW) Mirror() *TMirror draws the plot right to left: the x axis runs from the right, the value axis sits on the right, bars, lines, areas and points are mirrored (so categories read in reverse order), and pie, donut, radar and gauge start at the mirrored angle and sweep counter-clockwise. Labels stay readable; only their positions move. Without it the plot is drawn left to right even in RTL scopes, while the legend, tooltip and labels follow the scope direction.
func (*RadarW) NoArea
func (w *RadarW) NoArea() *RadarWNoArea draws outlines only.
func (*RadarW) NoTooltip
func (b *RadarW) NoTooltip() *TNoTooltip disables the hover tooltip and crosshair.
func (*RadarW) NoZero
func (o *RadarW) NoZero() *TNoZero lets the value axis start near the data instead of at zero.
func (*RadarW) Series
func (o *RadarW) Series(field string) *TSeries sets the field that splits rows into series (legend, colors).
func (*RadarW) Show
func (w *RadarW) Show() ViewShow builds the chart.
func (*RadarW) Style
func (b *RadarW) Style(fn func(*Style)) *TStyle tweaks the resolved chart style for this chart only.
func (*RadarW) X
func (o *RadarW) X(field string) *TX sets the x (category / time / number) field.
func (*RadarW) Y
func (o *RadarW) Y(field string) *TY sets the value field.
func (*RadarW) YMax
func (o *RadarW) YMax(v float64) *TYMax fixes the upper end of the value axis.
func (*RadarW) YMin
func (o *RadarW) YMin(v float64) *TYMin fixes the lower end of the value axis.
Row
type Row = map[string]anyRow is one datum: field name to value. Values may be any Go number, string (category), time.Time, or nil (missing).
func RowsOf
func RowsOf[T any](items []T, fn func(T) Row) []RowRowsOf converts typed items to rows.
rows := chart.RowsOf(sales, func(s Sale) chart.Row {
return chart.Row{"month": s.Month, "value": s.Amount}
})
ScatterW
type ScatterW struct {
// contains filtered or unexported fields
}ScatterW builds a scatter or bubble chart.
func Bubble
func Bubble(c *ui.Context, data []Row) *ScatterWBubble starts a bubble chart: Size maps a field to the bubble area.
func Scatter
func Scatter(c *ui.Context, data []Row) *ScatterWScatter 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) *TA11yLabel 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) *TAnimate enables (default) or disables entry and update transitions.
func (*ScatterW) Colors
func (b *ScatterW) Colors(cs ...theme.Color) *TColors overrides the palette.
func (*ScatterW) Format
func (b *ScatterW) Format(f Formatter) *TFormat sets the value formatter used by the value axis, tooltip and labels (default: thousands separators).
func (*ScatterW) Height
func (b *ScatterW) Height(h float32) *THeight sets the chart height in logical pixels (the width follows the parent).
func (*ScatterW) Key
func (b *ScatterW) Key(k any) *TKey gives the chart a stable identity (legend and animation state) when charts are added or removed around it.
func (*ScatterW) Label
func (b *ScatterW) Label() *TLabel shows data labels on the marks.
func (*ScatterW) Layout
func (b *ScatterW) Layout(o ...layout.Option) *TLayout applies layout options to the chart box (Grow, Margin ...).
func (*ScatterW) Legend
func (b *ScatterW) Legend(p LegendPos) *TLegend places (or with LegendNone hides) the legend.
func (*ScatterW) Loading
func (b *ScatterW) Loading(on bool) *TLoading shows a spinner over the chart (or in place of it without data).
func (*ScatterW) Mirror
func (b *ScatterW) Mirror() *TMirror 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() *TNoTooltip disables the hover tooltip and crosshair.
func (*ScatterW) NoZero
func (o *ScatterW) NoZero() *TNoZero lets the value axis start near the data instead of at zero.
func (*ScatterW) Radius
func (w *ScatterW) Radius(min, max float32) *ScatterWRadius sets the bubble radius range (default 4..24, points 4).
func (*ScatterW) Series
func (o *ScatterW) Series(field string) *TSeries sets the field that splits rows into series (legend, colors).
func (*ScatterW) Show
func (w *ScatterW) Show() ViewShow builds the chart.
func (*ScatterW) Size
func (w *ScatterW) Size(field string) *ScatterWSize maps a numeric field to the point area (bubbles).
func (*ScatterW) Style
func (b *ScatterW) Style(fn func(*Style)) *TStyle tweaks the resolved chart style for this chart only.
func (*ScatterW) X
func (o *ScatterW) X(field string) *TX sets the x (category / time / number) field.
func (*ScatterW) XFormat
func (w *ScatterW) XFormat(f Formatter) *ScatterWXFormat formats x tick labels and tooltip values.
func (*ScatterW) Y
func (o *ScatterW) Y(field string) *TY sets the value field.
func (*ScatterW) YMax
func (o *ScatterW) YMax(v float64) *TYMax fixes the upper end of the value axis.
func (*ScatterW) YMin
func (o *ScatterW) YMin(v float64) *TYMin fixes the lower end of the value axis.
func (*ScatterW) Zero
func (w *ScatterW) Zero() *ScatterWZero includes zero in both axes.
StepMode
type StepMode uint8StepMode selects a step line shape.
const (
StepNone StepMode = iota
StepEnd // horizontal then vertical ("hv")
StepStart // vertical then horizontal ("vh")
StepMiddle // change halfway between points ("hvh")
)Style
type Style struct {
Name string
Colors []theme.Color // categorical palette, cycled
Sequential []theme.Color // low → high (heatmap, continuous legend)
Font float32 // axis / legend text size
Label theme.Color // axis tick labels
Title theme.Color // axis titles, statistic captions
AxisLine theme.Color // axis base line
Tick theme.Color // tick marks
Grid theme.Color // grid lines
GridDash []float32 // nil = solid
XAxisLine bool // draw the bottom axis line (G2 relies on the 0 grid line)
YAxisLine bool
TickLen float32 // 0 hides tick marks
LabelGap float32 // tick (or axis) to label
LegendPos LegendPos // default placement for multi-series charts
LegendCenter bool // centre a top legend (ECharts)
LegendText theme.Color
LegendOff theme.Color // hidden series
LegendMarker Marker
LegendGap float32 // between items
TooltipBg theme.Color
TooltipTitle theme.Color
TooltipName theme.Color
TooltipValue theme.Color
TooltipFont float32
TooltipPad float32
TooltipRadius float32
TooltipShadow []paint.Shadow
TooltipBold bool // bold values (ECharts)
TooltipLine float32
Crosshair theme.Color
CrosshairDash []float32
BandHover theme.Color // background of the hovered band (bars)
Surface theme.Color // chart background, used for halo strokes
LineWidth float32
ShowPoints bool // draw hollow symbols on lines (ECharts default)
PointRadius float32 // symbol radius
AreaOpacity float64 // flat area fill opacity
AreaGrad bool // fade area fills to transparent (G2 look)
BarPadding float64 // inner band padding
BarOuter float64 // outer band padding
BarRadius float32
PointPad bool // lines over categories sit on band centres (ECharts boundaryGap)
SliceStroke float32 // white separators between pie slices
Track theme.Color
Positive theme.Color
Negative theme.Color
}Style is the visual language of charts: palette, axis, legend and tooltip tokens. StyleOf derives it from the UI theme; RegisterStyle adds new design languages (a shadcn style, a brand palette) without touching the charts.
func AntStyle
func AntStyle(th *theme.Theme) *StyleAntStyle is the G2 (Ant Design Charts v2) look derived from an Ant theme.
func EChartsStyle
func EChartsStyle(th *theme.Theme) *StyleEChartsStyle is the ECharts 5 default look, used for Element Plus.
func ShadcnStyle
func ShadcnStyle(th *theme.Theme) *StyleShadcnStyle is the shadcn/ui chart look (Recharts with shadcn's chart conventions): the --chart-1 … --chart-5 palette, horizontal grid lines only, no axis or tick lines, 12px muted labels, a bordered rounded tooltip with square markers, rounded bars and gradient areas. It is registered for theme.StyleShadcn themes.
func StyleOf
func StyleOf(th *theme.Theme) *StyleStyleOf returns the chart style for th.
func (*Style) Color
func (s *Style) Color(i int) theme.ColorColor returns palette color i (cycled).
StyleFunc
type StyleFunc func(th *theme.Theme) *StyleStyleFunc derives a chart style from a UI theme.
TimeScale
type TimeScale struct {
D0, D1 time.Time
R0, R1 float64
}TimeScale maps a time domain onto the range.
func (TimeScale) Map
func (s TimeScale) Map(t time.Time) float64Map returns the range position of t.
func (TimeScale) Ticks
func (s TimeScale) Ticks(count int, loc Labels) []TimeTickTicks returns about count calendar-aligned ticks with labels.
TimeTick
type TimeTick struct {
T time.Time
Label string
Major bool // a coarser boundary (new year, month or day)
}TimeTick is one time tick with its label.
func TimeTicks
func TimeTicks(t0, t1 time.Time, count int, lb Labels) []TimeTickTimeTicks 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
type TimeUnit uint8TimeUnit is a tick granularity.
const (
Second TimeUnit = iota
Minute
Hour
Day
Week
Month
Year
)func TimeInterval
func TimeInterval(t0, t1 time.Time, count int) (TimeUnit, int)TimeInterval picks the granularity giving at most about count ticks over [t0, t1].
TinyW
type TinyW struct {
// contains filtered or unexported fields
}TinyW builds a sparkline for statistic cards: no axes or legend, a compact tooltip on hover.
func TinyArea
func TinyArea(c *ui.Context, vals []float64) *TinyWTinyArea starts a filled sparkline.
func TinyColumn
func TinyColumn(c *ui.Context, vals []float64) *TinyWTinyColumn starts a mini column chart.
func TinyLine
func TinyLine(c *ui.Context, vals []float64) *TinyWTinyLine starts a sparkline.
func TinyProgress
func TinyProgress(c *ui.Context, ratio float64) *TinyWTinyProgress starts a thin progress bar (ratio 0..1).
func (*TinyW) A11yLabel
func (b *TinyW) A11yLabel(s string) *TA11yLabel 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) *TAnimate enables (default) or disables entry and update transitions.
func (*TinyW) Color
func (w *TinyW) Color(col theme.Color) *TinyWColor sets the mark color (default: first palette color).
func (*TinyW) Colors
func (b *TinyW) Colors(cs ...theme.Color) *TColors overrides the palette.
func (*TinyW) Format
func (b *TinyW) Format(f Formatter) *TFormat sets the value formatter used by the value axis, tooltip and labels (default: thousands separators).
func (*TinyW) Height
func (b *TinyW) Height(h float32) *THeight sets the chart height in logical pixels (the width follows the parent).
func (*TinyW) Key
func (b *TinyW) Key(k any) *TKey gives the chart a stable identity (legend and animation state) when charts are added or removed around it.
func (*TinyW) Label
func (b *TinyW) Label() *TLabel shows data labels on the marks.
func (*TinyW) Layout
func (b *TinyW) Layout(o ...layout.Option) *TLayout applies layout options to the chart box (Grow, Margin ...).
func (*TinyW) Legend
func (b *TinyW) Legend(p LegendPos) *TLegend places (or with LegendNone hides) the legend.
func (*TinyW) Loading
func (b *TinyW) Loading(on bool) *TLoading shows a spinner over the chart (or in place of it without data).
func (*TinyW) Mirror
func (b *TinyW) Mirror() *TMirror draws the plot right to left: the x axis runs from the right, the value axis sits on the right, bars, lines, areas and points are mirrored (so categories read in reverse order), and pie, donut, radar and gauge start at the mirrored angle and sweep counter-clockwise. Labels stay readable; only their positions move. Without it the plot is drawn left to right even in RTL scopes, while the legend, tooltip and labels follow the scope direction.
func (*TinyW) Names
func (w *TinyW) Names(names ...string) *TinyWNames labels the points in the tooltip (e.g. dates).
func (*TinyW) NoTooltip
func (b *TinyW) NoTooltip() *TNoTooltip disables the hover tooltip and crosshair.
func (*TinyW) Show
func (w *TinyW) Show() ViewShow builds the chart.
func (*TinyW) Smooth
func (w *TinyW) Smooth() *TinyWSmooth draws the line as a monotone curve.
func (*TinyW) Style
func (b *TinyW) Style(fn func(*Style)) *TStyle tweaks the resolved chart style for this chart only.
func (*TinyW) Target
func (w *TinyW) Target(v float64) *TinyWTarget draws a marker line at a target value (progress: ratio).
Tip
type Tip struct {
Title string
Items []TipItem
Index int // x / category / slice index
}Tip is the content of a tooltip.
TipItem
type TipItem struct {
Name, Value string
Color theme.Color
Marker Marker
}TipItem is one tooltip row.
View
type View struct {
*ui.Box
// contains filtered or unexported fields
}View is a shown chart: its box plus the hover / legend state of the frame.
func (View) Hidden
func (v View) Hidden(name string) boolHidden reports whether the legend has hidden series (or slice) name.
func (View) Tooltip
func (v View) Tooltip() (Tip, bool)Tooltip returns the tooltip shown in this frame.