logo

G2

  • Docs
  • Chart Introduction
  • API
  • Examples
  • Theme
  • Ecosystem
  • Productsantv logo arrow
  • 5.3.3
  • Get Started
  • Introduction
    • What is G2
    • Use In Framework
    • Experimental Spec API
  • Core Concepts
    • Chart
      • Components of G2 Charts
      • How to Use Charts
    • Mark
      • overview
      • area
      • box
      • boxplot
      • cell
      • chord
      • density
      • gauge
      • heatmap
      • image
      • interval
      • line
      • lineX
      • lineY
      • link
      • liquid
      • sunburst
      • point
      • polygon
      • range
      • rangeX
      • rangeY
      • rect
      • shape
      • text
      • vector
      • wordCloud
    • View
    • Data
      • overview
      • custom
      • ema
      • fetch
      • filter
      • fold
      • inline
      • join
      • kde
      • log
      • map
      • pick
      • rename
      • slice
      • sort
      • sortBy
    • Encode
    • Scale
      • overview
      • band
      • linear
      • log
      • ordinal
      • point
      • pow
      • quantile
      • quantize
      • sqrt
      • threshold
      • time
    • Transform
      • overview
      • bin
      • binX
      • diffY
      • dodgeX
      • flexX
      • group
      • groupColor
      • groupX
      • groupY
      • jitter
      • jitterX
      • jitterY
      • normalizeY
      • pack
      • sample
      • select
      • selectX
      • selectX
      • sortColor
      • sortX
      • sortY
      • stackEnter
      • stackY
      • symmetryY
    • Coordinate
      • overview
      • fisheye
      • parallel
      • polar
      • radial
      • theta
      • transpose
      • cartesian3D
      • helix
    • Style
    • Animate
      • overview
      • fadeIn
      • fadeOut
      • growInX
      • growInY
      • morphing
      • pathIn
      • scaleInX
      • scaleInY
      • scaleOutX
      • scaleOutY
      • waveIn
      • zoomIn
      • zoomOut
    • State
    • Interaction
      • Overview
      • brushAxisHighlight
      • brushHighlight
      • brushXHighlight
      • brushYHighlight
      • brushFilter
      • brushXFilter
      • brushYFilter
      • chartIndex
      • elementHighlight
      • elementHighlightByColor
      • elementHighlightByX
      • elementSelect
      • elementSelectByColor
      • elementSelectByX
      • fisheye
      • legendFilter
      • legendHighlight
      • poptip
      • scrollbarFilter
      • sliderFilter
    • Composition
      • overview
      • facetCircle
      • facetRect
      • repeatMatrix
      • spaceFlex
      • spaceLayer
      • timingKeyframe
    • Theme
      • overview
      • Academy
      • classic
      • classicDark
    • event
    • Color
  • Chart API
  • Chart Component
    • 标题(Title)
    • Axis
    • Legend
    • Scrollbar
    • Slider
    • Tooltip
    • Label
  • Extra Topics
    • Graph
      • forceGraph
      • pack
      • sankey
      • tree
      • treemap
    • Geo
      • geoPath
      • geoView
    • 3D
      • Draw 3D Chart
      • point3D
      • line3D
      • interval3D
      • surface3D
    • Plugin
      • renderer
      • rough
      • lottie
      • a11y
    • Package on demand
    • Set pattern
    • Server-side rendering(SSR)
    • Spec Function Expression Support (Available in 5.3.0)
  • Whats New
    • New Version Features
    • Migration from v4 to v5
  • Frequently Asked Questions (FAQ)

lineY

Previous
lineX
Next
link

Resources

Ant Design
Galacea Effects
Umi-React Application Framework
Dumi-Component doc generator
ahooks-React Hooks Library

Community

Ant Financial Experience Tech
seeconfSEE Conf-Experience Tech Conference

Help

GitHub
StackOverflow

more productsMore Productions

Ant DesignAnt Design-Enterprise UI design language
yuqueYuque-Knowledge creation and Sharing tool
EggEgg-Enterprise-class Node development framework
kitchenKitchen-Sketch Tool set
GalaceanGalacean-互动图形解决方案
xtechLiven Experience technology
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

概述

lineY和lineY图形标记配置相似,lineY图形标记用于绘制垂直于 y 轴的辅助线,常用于绘制平均值或其他聚合数据辅助线。

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'view',
height: 200,
autoFit: true,
children: [
{
type: 'interval',
data: [
{ year: '1951 年', sales: 38 },
{ year: '1952 年', sales: 52 },
{ year: '1956 年', sales: 61 },
{ year: '1957 年', sales: 120 },
{ year: '1958 年', sales: 48 },
{ year: '1959 年', sales: 38 },
],
encode: { x: 'year', y: 'sales' },
},
{
type: 'lineY',
data: [100, 59],
style: {
stroke: (v) => {
if (v >= 60) {
return 'green';
} else {
return 'red';
}
},
lineWidth: 2,
},
labels: [
// 文本具体配置可以参考 mark text
{
text: (v) => (v >= 60 ? 'lineY 分割线1' : 'lineY 分割线2'),
position: 'top-right',
textBaseline: 'bottom',
fill: '#000',
fillOpacity: 0.45,
background: true,
backgroundFill: '#000',
backgroundOpacity: 0.15,
},
],
},
],
});
chart.render();

更多的案例,可以查看图表示例 - 线标注页面。

配置项

属性描述类型默认值必选
encode配置 lineY 标记的视觉通道,包括y、color等,用于指定视觉元素属性和数据之间的关系encode-✓
style配置 lineY 标记的图形样式style-

encode

配置 lineY 标记的视觉通道。

属性描述类型默认值必选
x绑定 lineY 标记的 y 属性通道。 不需要 x 属性通道,可以直接 data([1,...]) 配置数据,会自动配置到 y通道。或者配合 transform 来计算原始数据的平均值(mean)或中位数(median),从而不用自己计算来自动自动绘画平均线或中位线encode-
color绑定 lineY 标记的 color 属性通道,如果将数据字段映射到颜色通道,会对数据进行分组,将数据拆分成多个不同颜色的区域encode-

尝试一下:

style

属性描述类型默认值必选
stroke图形的描边string | Function<string>-
strokeOpacity描边透明度number | Function<number>-
lineWidth图形描边的宽度number | Function<number>-
lineDash描边的虚线配置,第一个值为虚线每个分段的长度,第二个值为分段间隔的距离。lineDash 设为[0, 0]的效果为没有描边。[number,number] | Function<[number, number]>-
opacity图形的整体透明度number | Function<number>-
shadowColor图形阴影颜色string | Function<string>-
shadowBlur图形阴影的高斯模糊系数number | Function<number>-
shadowOffsetX设置阴影距图形的水平距离number | Function<number>-
shadowOffsetY设置阴影距图形的垂直距离number | Function<number>-
cursor鼠标样式。同 css 的鼠标样式,默认 'default'。string | Function<string>default