Chart

以图表呈现分类数据和趋势。

实时预览

正在加载预览…

参数配置

全部字段 25

ChartOptions

Styles · 0

Categories

列表项 · 5

ChartSeriesItems

列表项 · 2
ChartSeries
列表项 · 5
ChartSeries
列表项 · 5

ChartSliceItems

列表项 · 3
ChartSlice
ChartSlice
ChartSlice

Go 代码

Go
// Inside a view; c is *ui.Context, t is nui.Theme.
// Keep s (example state) outside the view. See the complete example.
chart := &s.Chart
if nui.ChartLine == nui.ChartPie || nui.ChartLine == nui.ChartDonut {
	chart = &s.Slices
}
nui.Chart(c.Key("chart"), t, chart, nui.ChartOptions{Label: "Weekly activity", Kind: nui.ChartLine, Height: 260, Legend: nui.Optional[bool]{}, Grid: nui.Optional[bool]{}, Animate: nui.Optional[bool]{}})

使用说明

切换折线、柱形、面积、散点、饼图和环形图,比较图例、网格与动画。完整示例用持久 ChartState 管理序列数据,饼图与环形图使用单独的分类数据。

API 参考

Chart

源码
func Chart(c *ui.Context, t Theme, s *ChartState, o ChartOptions) ui.Element

ChartOptions

源码
type ChartOptions struct {
	Label, EmptyText string
	Kind             ChartKind
	Curve            ChartCurve
	// Stack applies to bars and areas; other types ignore it.
	Stack                           ChartStackMode
	Height                          float32
	Legend, InteractiveLegend, Grid Optional[bool]
	FormatX, FormatY                func(float64) string
	FormatTime                      func(time.Time) string
	// Animate defaults to true and respects theme/system reduced motion.
	Animate              Optional[bool]
	AnimationDuration    time.Duration     // default 350ms
	BarPadding           Optional[float32] // category band inner padding, default .25
	DonutInnerRadius     Optional[float64] // fraction of outer radius, default .6
	SlicePadding         Optional[float64] // angle in radians, default .02
	LineWidth, PointSize Optional[float32]
	OnLegendChange       func(id string, visible bool)
	Decoration
}
字段类型说明
Labelstring

Go 零值: ""

控件标签或可访问名称。

EmptyTextstring

Go 零值: ""

没有可显示数据时的文案。

KindChartKind

Go 零值: zero value

组件图型或项目种类。

CurveChartCurve

Go 零值: zero value

线条或面积图的插值曲线。

StackChartStackMode

Go 零值: zero value

柱状图或面积图的堆叠策略。

Heightfloat32

Go 零值: 0

高度,单位为 DIP。

LegendOptional[bool]

Go 零值: unset

显示图例。

InteractiveLegendOptional[bool]

Go 零值: unset

允许通过图例切换数据系列。

GridOptional[bool]

Go 零值: unset

显示图表网格。

FormatXfunc(float64) string

Go 零值: nil

横轴数值格式化函数。

FormatYfunc(float64) string

Go 零值: nil

纵轴数值格式化函数。

FormatTimefunc(time.Time) string

Go 零值: nil

时间轴格式化函数。

AnimateOptional[bool]

Go 零值: unset

控制动画,并遵守系统的减少动态效果偏好。

AnimationDurationtime.Duration

Go 零值: 0

动画持续时间。

BarPaddingOptional[float32]

Go 零值: unset

分类带内部的柱间距比例。

DonutInnerRadiusOptional[float64]

Go 零值: unset

环形图内半径与外半径的比例。

SlicePaddingOptional[float64]

Go 零值: unset

扇区间距,单位为弧度。

LineWidthOptional[float32]

Go 零值: unset

图表线条宽度。

PointSizeOptional[float32]

Go 零值: unset

图表数据点大小。

OnLegendChangefunc(id string, visible bool)

Go 零值: nil

图例可见性改变时通知应用的回调。

UIStyles

Go 零值: zero value

以部件名称为键覆盖外观和间距。

Stylefunc(Slot, ui.Element)

Go 零值: nil

同步配置当前构建的部件;不要保留 Element。