渐变面积#

单序列、平滑曲线和从序列色渐隐的填充。

启用 JavaScript 后可运行预览;源码和安装命令仍可直接查看。

用法
chart := components.AreaChart{
    Series: []components.ChartSeries{{Key: "desktop", Label: "Desktop", Color: theme.Chart[0]}},
    Values: [][]float32{desktop},
    Curve:  components.ChartCurveMonotone,
    XAxis:  components.ChartAxis{Format: formatMonth},
    Grid:   components.ChartGridHorizontal,
}
plot := components.PaintAreaChart(canvas, theme, bounds, chartID, chart, &state)

折线与数据点#

无填充的折线图,标出每个数据点。

启用 JavaScript 后可运行预览;源码和安装命令仍可直接查看。

用法
chart := components.AreaChart{
    Series: series, Values: values,
    Fill:   components.ChartFillNone,
    Dots:   true,
    XAxis:  components.ChartAxis{Format: formatMonth},
    Grid:   components.ChartGridBoth,
    Legend: components.ChartLegendBottom,
}
components.PaintAreaChart(canvas, theme, bounds, chartID, chart, &state)

阶梯曲线#

每个值保持到相邻两点的中点。

启用 JavaScript 后可运行预览;源码和安装命令仍可直接查看。

用法
chart := components.AreaChart{
    Series: series, Values: values,
    Curve:  components.ChartCurveStep,
    Fill:   components.ChartFillSolid,
    XAxis:  components.ChartAxis{Format: formatMonth},
}
components.PaintAreaChart(canvas, theme, bounds, chartID, chart, &state)

堆叠#

按序列顺序自下而上堆叠,纵轴随总量缩放。

启用 JavaScript 后可运行预览;源码和安装命令仍可直接查看。

用法
chart := components.AreaChart{
    Series: series, Values: values,
    Curve:  components.ChartCurveNatural,
    Stack:  components.ChartStackStacked,
    XAxis:  components.ChartAxis{Format: formatMonth},
    Grid:   components.ChartGridHorizontal,
    Legend: components.ChartLegendBottom,
}
components.PaintAreaChart(canvas, theme, bounds, chartID, chart, &state)

百分比堆叠#

每个横坐标归一到 100%,纵轴以百分比标注。

启用 JavaScript 后可运行预览;源码和安装命令仍可直接查看。

用法
chart := components.AreaChart{
    Series: series, Values: values,
    Stack:  components.ChartStackExpand,
    XAxis:  components.ChartAxis{Format: formatMonth},
    Grid:   components.ChartGridHorizontal,
}
components.PaintAreaChart(canvas, theme, bounds, chartID, chart, &state)

悬停与键盘#

指针或方向键移动悬停点,提示框按边缘自动翻转。

启用 JavaScript 后可运行预览;源码和安装命令仍可直接查看。

用法
plot := components.PaintAreaChart(canvas, theme, bounds, chartID, chart, &state)
// From the pointer: state.Hover(plot.IndexAt(event.X)), and state.Clear() on exit.
// From the keyboard:
if index, ok := components.ChartStepForKey(event.Key, current, plot.Count()); ok {
    state.Hover(index)
}

安装

将组件源码复制到自己的项目,直接修改。

仓库命令
go run ./cmd/viva add --out ./components/local chart-area

源码组件用法#

此预览直接调用生产 Go 组件。稳定 ID、值与打开状态仍由应用持有;组件只负责绘制并声明交互语义。

  • 标题旁的源码链接列出了全部选项与视觉决策。
  • 请使用原生命令验证系统文本、焦点、无障碍与平台集成。
  • 浏览器预览验证共享布局和场景行为,不代表原生性能。

验证边界#

示例覆盖当前 API 的代表性状态,但不表示每个桌面后端都已完成真机验证。

键盘操作

Tab 在控件间移动;Ctrl/⌘ K 搜索组件。进入预览后,键盘事件由 Go 运行时处理。