Documentation
¶
Overview ¶
Package chart draws charts: line, area, bar (grouped, stacked, horizontal), pie and donut, funnel, scatter and bubble, gauge, heatmap and sparklines, with axes, legends, tooltips, selection, brushing, zoom and pan, animated data changes, theme colors, right-to-left layout and a data table for screen readers.
Index ¶
- func FormatNumber(v float64) string
- func Sparkline(values []float64, st ...styles.Styles) elements.Element
- func TimeX(t time.Time) float64
- type Axis
- type Band
- type Chart
- func (c *Chart) Animate(on bool) *Chart
- func (c *Chart) Categories(names ...string) *Chart
- func (c *Chart) Description(s string) *Chart
- func (c *Chart) Height(dp int) *Chart
- func (c *Chart) Layout(gtx layout.Context) layout.Dimensions
- func (c *Chart) Legend(p LegendPos) *Chart
- func (c *Chart) OnBrush(fn func(from, to float64)) *Chart
- func (c *Chart) OnSelect(fn func(series, index int)) *Chart
- func (c *Chart) ResetZoom()
- func (c *Chart) Selected() (series, index int)
- func (c *Chart) Series() []Series
- func (c *Chart) SetGauge(value, min, max float64, bands ...Band) *Chart
- func (c *Chart) SetHeatmap(rows, cols []string, values [][]float64) *Chart
- func (c *Chart) SetSeries(ss ...Series) *Chart
- func (c *Chart) Smooth(on bool) *Chart
- func (c *Chart) Style(st styles.Styles) *Chart
- func (c *Chart) Summary() string
- func (c *Chart) Table() elements.Element
- func (c *Chart) Title(s string) *Chart
- func (c *Chart) X(a Axis) *Chart
- func (c *Chart) Y(a Axis) *Chart
- func (c *Chart) Y2(a Axis) *Chart
- func (c *Chart) Zoomable(on bool) *Chart
- type Kind
- type LegendPos
- type Point
- type Series
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatNumber ¶
FormatNumber writes v compactly: 950, 1.2k, 3.4M, 2B, with up to decimals digits after the point for small numbers.
Types ¶
type Axis ¶
type Axis struct {
Title string
// Format writes tick labels and tooltip values; FormatNumber, or
// dates on a time axis, by default.
Format func(v float64) string
// Min and Max fix the range when Fixed is set; otherwise it's the
// data's, rounded out to ticks (and including zero for bars).
Min, Max float64
Fixed bool
// Time makes X a time axis of Unix seconds, in Location (local
// time when nil).
Time bool
Location *time.Location
// Hide hides the axis line and labels; NoGrid its grid lines.
Hide, NoGrid bool
}
Axis configures an axis.
type Chart ¶
type Chart struct {
elements.Contextual
// contains filtered or unexported fields
}
Chart is a stateful chart. Create it once with New and lay it out every frame; set data whenever it changes.
func (*Chart) Animate ¶
Animate turns animating data changes on (the default) or off. With reduced motion on, they don't animate either way.
func (*Chart) Categories ¶
Categories names the categories: the x axis of a category chart, pie slices, funnel stages.
func (*Chart) Description ¶
Description sets what screen readers hear about the chart, in place of the summary of its data.
func (*Chart) Height ¶
Height sets the chart's height in dp, 280 by default; it shrinks to the height it's given.
func (*Chart) Layout ¶
func (c *Chart) Layout(gtx layout.Context) layout.Dimensions
Layout draws the chart in the width it's given.
func (*Chart) OnBrush ¶
OnBrush lets dragging across an x-y or category chart select a range, passed as x values (category indexes on a category chart).
func (*Chart) OnSelect ¶
OnSelect sets the handler of a click on a bar, point, slice, stage or cell: its series and index (a heatmap's row and column).
func (*Chart) SetHeatmap ¶
SetHeatmap sets a heatmap's rows, columns and values by row.
func (*Chart) Summary ¶
Summary describes the chart in words, for screen readers: its title, kind, and each series' range; or the Description set.
func (*Chart) Table ¶
Table returns the chart's data as a table, a text alternative to show beside it or instead of it: a row per category or x, a column per series.
func (*Chart) Title ¶
Title sets the title drawn above the chart, which also names it to screen readers.
type Point ¶
type Point struct {
X, Y float64
// Size is a bubble's size in a scatter chart, relative to the
// largest; 0 draws plain points.
Size float64
// Label names the point in tooltips.
Label string
}
Point is a point of an x-y series: X a number or, on a time axis, Unix seconds (TimeX converts).
type Series ¶
type Series struct {
Name string
// Values are one per category: bars, lines over categories, pie
// slices and funnel stages (named by the chart's Categories).
Values []float64
// Points are an x-y series: lines and areas over numbers or time,
// scatter plots.
Points []Point
// Color overrides the theme's series color ("theme.chart1" and on).
Color string
// Kind draws this series differently from the chart: a Line over
// Bar chart's bars, for example.
Kind Kind
// Axis 1 measures the series on the right-hand axis (Y2).
Axis int
// Stack stacks the series on the others with the same Stack:
// stacked bars and areas.
Stack string
// Dashed draws a line dashed, as forecasts are.
Dashed bool
// Hidden leaves the series out; clicking its legend entry toggles
// it.
Hidden bool
}
Series is a set of values a chart draws.