logo

Ant Design Charts

  • Manual
  • Components
  • Examples
  • Options
  • Productsantv logo arrow
  • 2.0.0
  • Common Configuration Statistical Charts
    • 标题(Title)
    • Axis
    • Legend
    • Scrollbar
    • Slider
    • Tooltip
    • Label
    • Color
    • event
    • Interaction
      • Overview
      • brushAxisHighlight
      • brushHighlight
      • brushXHighlight
      • brushYHighlight
      • brushFilter
      • brushXFilter
      • brushYFilter
      • chartIndex
      • elementHighlight
      • elementHighlightByColor
      • elementHighlightByX
      • elementSelect
      • elementSelectByColor
      • elementSelectByX
      • fisheye
      • legendFilter
      • legendHighlight
      • poptip
      • scrollbarFilter
      • sliderFilter
    • State
    • Style
    • Scale
      • overview
      • band
      • linear
      • log
      • ordinal
      • point
      • pow
      • quantile
      • quantize
      • sqrt
      • threshold
      • time
    • Animate
      • overview
      • fadeIn
      • fadeOut
      • growInX
      • growInY
      • morphing
      • pathIn
      • scaleInX
      • scaleInY
      • scaleOutX
      • scaleOutY
      • waveIn
      • zoomIn
      • zoomOut
    • Theme
      • overview
      • Academy
      • classic
      • classicDark
    • Data
      • overview
      • custom
      • ema
      • fetch
      • filter
      • fold
      • inline
      • join
      • kde
      • log
      • map
      • pick
      • rename
      • slice
      • sort
      • sortBy

chartIndex

Previous
brushYFilter
Next
elementHighlight

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...

概述

chartIndex 是一种交互组件,用于查看折线图相对于某个时间点的相对趋势。

example
import { Line } from '@ant-design/plots';
import React from 'react';
import { createRoot } from 'react-dom';
const Demo = () => {
const config ={
data: {
type: 'fetch',
value: 'https://assets.antv.antgroup.com/g2/indices.json',
},
xField: (d) => new Date(d.Date),
yField: 'Close',
colorField: 'Symbol',
keyField: 'Symbol',
titleField: (d) => d.Date.toLocaleString(),
axis: {
y: {
title: '↑ Change in price (%)',
labelAutoRotate: false,
},
},
scale: {
y: {
type: 'log',
},
},
label: {
text: 'Symbol',
selector: 'last',
style: {
fontSize: 10,
},
},
interaction: {
chartIndex: {
ruleStroke: '#aaa',
labelDx: 5,
labelTextAlign: 'center',
labelStroke: '#fff',
labelLineWidth: 5,
labelFormatter: (d) => `${d.toLocaleDateString()}`,
},
}
};
return <Line {...config} />;
};
createRoot(document.getElementById('container')).render(<Demo />);

使用方式

chartIndex 通过传入 配置项 对交互进行配置

({
interaction: {
chartIndex: {},
},
});

配置层级

交互可以配置在 Mark 层级:

({
interaction: { chartIndex: {} },
});

配置项

属性描述类型默认值必选
ruleStroke指示线的颜色stringblack
ruleLineWidth指示线宽number1
ruleLineDash虚线配置,第一个值为虚线每个分段的长度,第二个值为分段间隔的距离。ruleLineDash 设为[0,0]的效果为没有描边。[number,number]
ruleStrokeOpacity指示线的透明度number
ruleOpacity整体透明度number
ruleShadowColor指示线阴影颜色string
ruleShadowBlur指示线高斯模糊系数number
ruleShadowOffsetX指示线阴影距图形的水平距离number
ruleShadowOffsetY指示线阴影距图形的垂直距离number
labelFontSize文字大小number
labelFontFamily文字字体string
labelFontWeight字体粗细number
labelLineHeight文字的行高number
labelTextAlign设置文本内容的当前对齐方式center | end | left | right | start
labelTextBaseline设置在绘制文本时使用的当前文本基线top | middle | bottom | alphabetic | hanging
labelFill文字的填充色string
labelFillOpacity文字的填充透明度number
labelStroke文字的描边string
labelLineWidth文字描边的宽度number
labelLineDash描边的虚线配置,第一个值为虚线每个分段的长度,第二个值为分段间隔的距离。labelLineDash 设为[0,0]的效果为没有描边。[number,number]
labelStrokeOpacity描边透明度number
labelOpacity文字的整体透明度number
labelShadowColor文字阴影颜色string
labelShadowBlur文字阴影的高斯模糊系数number
labelShadowOffsetX设置阴影距文字的水平距离number
labelShadowOffsetY设置阴影距文字的垂直距离number
labelDx文字在 x 方向偏移number
labelDy文字在 y 方向偏移number
labelFormatter格式化日期FormatterFunction

示例

指示线和文字

import { Line } from '@ant-design/plots';
import React from 'react';
import { createRoot } from 'react-dom';
const Demo = () => {
const config ={
autoFit: true,
data: {
type: 'fetch',
value: 'https://assets.antv.antgroup.com/g2/indices.json',
},
xField: (d) => new Date(d.Date),
yField: 'Close',
colorField: 'Symbol',
keyField: 'Symbol',
titleField: (d) => d.Date.toLocaleString(),
axis: {
y: {
title: '↑ Change in price (%)',
labelAutoRotate: false,
},
},
scale: {
y: {
type: 'log',
},
},
label: {
text: 'Symbol',
selector: 'last',
style: {
fontSize: 10,
},
},
interaction: {
tooltip: {
crosshairs: false, // 关闭辅助线
},
chartIndex: {
ruleStroke: 'pink',
ruleLineWidth: 8,
ruleLineDash: [4, 8],
ruleShadowColor: 'green',
ruleShadowBlur: 5,
ruleShadowOffsetX: 5,
ruleShadowOffsetY: 5,
ruleOpacity: 0.9,
labelDy: 30,
labelFontSize: 20,
labelTextAlign: 'center',
labelFill: 'red',
labelStroke: 'yellow',
labelLineWidth: 2,
labelFormatter: (d) => `${d.toLocaleDateString()}`,
},
}
};
return <Line {...config} />;
};
createRoot(document.getElementById('container')).render(<Demo />);