Skip to content

Radar 雷达图 ​

在多个共同量纲的维度上同时比较一组或多组指标。

何时使用 ​

  • 比较同一评价模型下多个维度的能力、评分或完成度。
  • 需要在少量维度中看整体轮廓和系列差异时。
  • 维度很多或需要精确读数时改用 Table 表格 或 Column 柱状图。

在线体验 ​

Gallery 展示多系列雷达图,以及圆形网格、仅描边和固定最大值的场景。

Radar 雷达图 · 在线体验真实 Go 组件
在独立页面打开 ↗

查看此场景的 Go 源码 ↗

基本用法 ​

X() 是维度字段,Y() 是数值字段,Series() 将多行拆成多个雷达轮廓。少于三个维度时显示空状态。

go
package main

import (
    "github.com/tangoui/tango/ui"
    "github.com/tangoui/tango/ui/chart"
)

var skillRows = []chart.Row{
    {"item": "设计", "user": "甲", "score": 70},
    {"item": "开发", "user": "甲", "score": 60},
    {"item": "设计", "user": "乙", "score": 50},
    {"item": "开发", "user": "乙", "score": 80},
}

func page(c *ui.Context) {
    chart.Radar(c, skillRows).X("item").Y("score").Series("user").YMax(100).Show()
}

常见用法 ​

固定最大值 ​

雷达图从零起算。评分、百分比等有明确上限时用 YMax() 固定上限,避免不同数据批次改变网格尺度。

go
package main

import (
    "github.com/tangoui/tango/ui"
    "github.com/tangoui/tango/ui/chart"
)

func fixedRadar(c *ui.Context) {
    rows := []chart.Row{{"item": "质量", "score": 82}, {"item": "速度", "score": 65}, {"item": "稳定性", "score": 91}}
    chart.Radar(c, rows).X("item").Y("score").YMax(100).Format(chart.Thousands(0)).Show()
}

圆形网格和仅描边 ​

Circle() 将多边形网格改为圆形,NoArea() 只绘制轮廓,适合多个系列重叠时减少填充遮挡。

go
package main

import (
    "github.com/tangoui/tango/ui"
    "github.com/tangoui/tango/ui/chart"
)

func outlineRadar(c *ui.Context) {
    rows := []chart.Row{{"item": "质量", "user": "甲", "score": 82}, {"item": "速度", "user": "甲", "score": 65}}
    chart.Radar(c, rows).X("item").Y("score").Series("user").Circle().NoArea().Show()
}

图例和提示 ​

多系列雷达保留图例,用户可切换系列;默认悬停提示显示对应维度的数值,需要展示静态图时可使用 NoTooltip()。

go
package main

import (
    "github.com/tangoui/tango/ui"
    "github.com/tangoui/tango/ui/chart"
)

func radarA11y(c *ui.Context) {
    rows := []chart.Row{{"item": "设计", "user": "甲", "score": 70}, {"item": "开发", "user": "甲", "score": 60}}
    chart.Radar(c, rows).X("item").Y("score").Series("user").A11yLabel("团队能力雷达图").NoTooltip().Show()
}

主题与样式 ​

Radar 的网格、填充透明度、轮廓线和分类色由当前 chart style 提供。可用 Colors() 固定系列色,或用 Style(func(*chart.Style) { ... }) 做局部调整;当填充重叠时优先 NoArea(),不要只靠颜色区分。

注意事项 ​

  • 所有维度应使用同一量纲和相同方向,缺失值应先处理,不要把不同单位强行放进同一雷达图。
  • 维度顺序会影响轮廓形状,应在数据源中稳定排序;筛选系列不应改变剩余系列的颜色。
  • 即时模式下把评分数据放在外部状态,条件切换图表时设置稳定 Key();用 A11yLabel() 和图例补充颜色之外的身份信息。
  • RTL 只影响外围文字和图例;如需镜像网格方向再调用 Mirror()。

示例代码 ​

以下是上方在线演示运行的 Go 源码(来自官方 gallery),点击标题展开。函数接收的 c *ui.Context 由窗口的 UI 循环每帧传入,接入方式见 Go GUI 入门。

Radar 雷达图

gallery 演示 ChartRadar 的 Render 函数,源码 page_chart_more.go#L118。

加载中…

API ​

签名与说明由 site/tools/compdoc 从 Go 源码和文档注释提取;点击名称跳到 Go API 参考 的对应条目。

入口函数 ​

chart.Radar ​

go
func Radar(c *ui.Context, data []Row) *RadarW

Radar starts a radar chart: X is the dimension field, Y the value.

chart.Radar(c, rows).X("item").Y("score").Series("user").Show()

返回 *RadarW,可链式调用的方法见 RadarW 方法。

RadarW 方法 ​

chart.RadarW:RadarW builds a radar (spider) chart.

方法说明签名
A11yLabelA11yLabel sets the accessible name of the chart (default: its title or the localized chart kind, e.g. "折线图"). (来自嵌入的 common[RadarW])A11yLabel(s string) *RadarW
AnimateAnimate enables (default) or disables entry and update transitions. (来自嵌入的 common[RadarW])Animate(on bool) *RadarW
CircleCircle draws a circular grid instead of polygons.Circle() *RadarW
ColorsColors overrides the palette. (来自嵌入的 common[RadarW])Colors(cs ...theme.Color) *RadarW
FormatFormat sets the value formatter used by the value axis, tooltip and labels (default: thousands separators). (来自嵌入的 common[RadarW])Format(f Formatter) *RadarW
HeightHeight sets the chart height in logical pixels (the width follows the parent). (来自嵌入的 common[RadarW])Height(h float32) *RadarW
KeyKey gives the chart a stable identity (legend and animation state) when charts are added or removed around it. (来自嵌入的 common[RadarW])Key(k any) *RadarW
LabelLabel shows data labels on the marks. (来自嵌入的 common[RadarW])Label() *RadarW
LayoutLayout applies layout options to the chart box (Grow, Margin ...). (来自嵌入的 common[RadarW])Layout(o ...layout.Option) *RadarW
LegendLegend places (or with LegendNone hides) the legend. (来自嵌入的 common[RadarW])Legend(p LegendPos) *RadarW
LoadingLoading shows a spinner over the chart (or in place of it without data). (来自嵌入的 common[RadarW])Loading(on bool) *RadarW
MirrorMirror 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. (来自嵌入的 common[RadarW])Mirror() *RadarW
NoAreaNoArea draws outlines only.NoArea() *RadarW
NoTooltipNoTooltip disables the hover tooltip and crosshair. (来自嵌入的 common[RadarW])NoTooltip() *RadarW
NoZeroNoZero lets the value axis start near the data instead of at zero. (来自嵌入的 xyOpts[RadarW])NoZero() *RadarW
SeriesSeries sets the field that splits rows into series (legend, colors). (来自嵌入的 xyOpts[RadarW])Series(field string) *RadarW
ShowShow builds the chart.Show() View
StyleStyle tweaks the resolved chart style for this chart only. (来自嵌入的 common[RadarW])Style(fn func(*Style)) *RadarW
XX sets the x (category / time / number) field. (来自嵌入的 xyOpts[RadarW])X(field string) *RadarW
YY sets the value field. (来自嵌入的 xyOpts[RadarW])Y(field string) *RadarW
YMaxYMax fixes the upper end of the value axis. (来自嵌入的 xyOpts[RadarW])YMax(v float64) *RadarW
YMinYMin fixes the lower end of the value axis. (来自嵌入的 xyOpts[RadarW])YMin(v float64) *RadarW

相关链接 ​

以 MIT 许可发布