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

brushYFilter

Previous
brushXFilter
Next
chartIndex

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

概述

brushYFilter 交互是 brushFilter 的纵向限定版本,专用于基于 Y 轴维度的数据筛选。该交互限制用户只能通过垂直方向的框选操作(沿 Y 轴方向),对图表元素进行范围过滤,特别适用于数值区间分析、纵向对比等场景。

example

核心特征:

垂直操作:仅允许垂直方向框选,X 轴范围自动全选

数值聚焦:精准控制 Y 轴数值范围(如价格区间、温度范围)

动态响应:筛选结果实时映射到关联视图

import { Scatter } from '@ant-design/plots';
import React from 'react';
import { createRoot } from 'react-dom';
const Demo = () => {
const config ={
autoFit: true,
data: {
type: 'fetch',
value: 'https://gw.alipayobjects.com/os/antvdemo/assets/data/scatter.json',
},
xField: 'height',
// Y 轴绑定数值型数据
yField: 'weight',
interaction: {
brushYFilter: { maskStroke: '#52c41a' }, // 启用绿色边框的纵向筛选
}
};
return <Scatter {...config} />;
};
createRoot(document.getElementById('container')).render(<Demo />);

使用方式

配置 brushYFilter 交互有两种方式

快速启用模式

通过布尔值开启交互,使用默认配置:

({
interaction: { brushYFilter: true }, // 启用默认配置的Y轴刷选过滤
});

自定义配置模式

通过配置项 精细化控制交互行为:

({
interaction: {
brushYFilter: {
reverse: false, // 关闭反向选择
maskFill: '#rgba(0,0,0,0.3)', // 自定义蒙版颜色
},
},
});

配置层级

交互可以配置在 Mark 层级:

({
interaction: { brushYFilter: true },
});

配置项

属性描述类型默认值必选
reversebrush 是否反转booleanfalse
mask框选区域的蒙版样式mask详见 mask

mask

配置框选区域的蒙版的样式。

属性描述类型默认值必选
maskFill蒙版的填充色string#777
maskFillOpacity蒙版的填充透明度number0.3
maskStroke蒙版的描边string#fff
maskStrokeOpacity描边透明度number
maskLineWidth蒙版描边的宽度number
maskLineDash描边的虚线配置,第一个值为虚线每个分段的长度,第二个值为分段间隔的距离。lineDash 设为[0,0]的效果为没有描边。[number,number]
maskOpacity蒙版的整体透明度number
maskShadowColor蒙版阴影颜色string
maskShadowBlur蒙版阴影的高斯模糊系数number
maskShadowOffsetX设置阴影距蒙版的水平距离number
maskShadowOffsetY设置阴影距蒙版的垂直距离number
maskCursor鼠标样式。同 css 的鼠标样式stringdefault

在配置框选区域的蒙版样式的时候,不是以对象的形式来配置,而是以 mask前缀加属性的方式来配置。

样式配置示例:

({
interaction: {
brushYFilter: {
maskFill: '#000',
maskFillOpacity: 0.2,
maskStroke: 'red',
maskStrokeOpacity: 0.9,
maskLineWidth: 2,
maskLineDash: [4, 8],
maskOpacity: 0.2,
maskShadowColor: '#d3d3d3',
maskShadowBlur: 10,
maskShadowOffsetX: 10,
maskShadowOffsetY: 10,
maskCursor: 'pointer',
},
},
});

事件

监听事件

监听刷选过滤动作:

chart.on('brush:filter', (event) => {
const {
data, // 筛选后的数据集合
nativeEvent, // 原始 DOM 事件
} = event;
const [yMin, yMax] = data.selection[1]; // 注意数据结构差异
console.log(`数值区间:${yMin.toFixed(2)} - ${yMax.toFixed(2)}`);
});
chart.on('brush:filter', (event) => {
const {
data, // 筛选后的数据集合
nativeEvent, // 原始 DOM 事件
} = event;
const [yMin, yMax] = data.selection[1]; // 注意数据结构差异
console.log(`数值区间:${yMin.toFixed(2)} - ${yMax.toFixed(2)}`);
});
chart.on('brush:filter', (event) => {
const {
data, // 筛选后的数据集合
nativeEvent, // 原始 DOM 事件
} = event;
const [yMin, yMax] = data.selection[1]; // 注意数据结构差异
console.log(`数值区间:${yMin.toFixed(2)} - ${yMax.toFixed(2)}`);
});
chart.on('brush:filter', (event) => {
const {
data, // 筛选后的数据集合
nativeEvent, // 原始 DOM 事件
} = event;
const [yMin, yMax] = data.selection[1]; // 注意数据结构差异
console.log(`数值区间:${yMin.toFixed(2)} - ${yMax.toFixed(2)}`);
});
chart.on('brush:filter', (event) => {
const {
data, // 筛选后的数据集合
nativeEvent, // 原始 DOM 事件
} = event;
const [yMin, yMax] = data.selection[1]; // 注意数据结构差异
console.log(`数值区间:${yMin.toFixed(2)} - ${yMax.toFixed(2)}`);
});
chart.on('brush:filter', (event) => {
const {
data, // 筛选后的数据集合
nativeEvent, // 原始 DOM 事件
} = event;
const [yMin, yMax] = data.selection[1]; // 注意数据结构差异
console.log(`数值区间:${yMin.toFixed(2)} - ${yMax.toFixed(2)}`);
});
chart.on('brush:filter', (event) => {
const {
data, // 筛选后的数据集合
nativeEvent, // 原始 DOM 事件
} = event;
const [yMin, yMax] = data.selection[1]; // 注意数据结构差异
console.log(`数值区间:${yMin.toFixed(2)} - ${yMax.toFixed(2)}`);
});
chart.on('brush:filter', (event) => {
const {
data, // 筛选后的数据集合
nativeEvent, // 原始 DOM 事件
} = event;
const [yMin, yMax] = data.selection[1]; // 注意数据结构差异
console.log(`数值区间:${yMin.toFixed(2)} - ${yMax.toFixed(2)}`);
});
chart.on('brush:filter', (event) => {
const {
data, // 筛选后的数据集合
nativeEvent, // 原始 DOM 事件
} = event;
const [yMin, yMax] = data.selection[1]; // 注意数据结构差异
console.log(`数值区间:${yMin.toFixed(2)} - ${yMax.toFixed(2)}`);
});
chart.on('brush:filter', (event) => {
const {
data, // 筛选后的数据集合
nativeEvent, // 原始 DOM 事件
} = event;
const [yMin, yMax] = data.selection[1]; // 注意数据结构差异
console.log(`数值区间:${yMin.toFixed(2)} - ${yMax.toFixed(2)}`);
});
chart.on('brush:filter', (event) => {
const {
data, // 筛选后的数据集合
nativeEvent, // 原始 DOM 事件
} = event;
const [yMin, yMax] = data.selection[1]; // 注意数据结构差异
console.log(`数值区间:${yMin.toFixed(2)} - ${yMax.toFixed(2)}`);
});
chart.on('brush:filter', (event) => {
const {
data, // 筛选后的数据集合
nativeEvent, // 原始 DOM 事件
} = event;
const [yMin, yMax] = data.selection[1]; // 注意数据结构差异
console.log(`数值区间:${yMin.toFixed(2)} - ${yMax.toFixed(2)}`);
});
chart.on('brush:filter', (event) => {
const {
data, // 筛选后的数据集合
nativeEvent, // 原始 DOM 事件
} = event;
const [yMin, yMax] = data.selection[1]; // 注意数据结构差异
console.log(`数值区间:${yMin.toFixed(2)} - ${yMax.toFixed(2)}`);
});
chart.on('brush:filter', (event) => {
const {
data, // 筛选后的数据集合
nativeEvent, // 原始 DOM 事件
} = event;
const [yMin, yMax] = data.selection[1]; // 注意数据结构差异
console.log(`数值区间:${yMin.toFixed(2)} - ${yMax.toFixed(2)}`);
});
chart.on('brush:filter', (event) => {
const {
data, // 筛选后的数据集合
nativeEvent, // 原始 DOM 事件
} = event;
const [yMin, yMax] = data.selection[1]; // 注意数据结构差异
console.log(`数值区间:${yMin.toFixed(2)} - ${yMax.toFixed(2)}`);
});
chart.on('brush:filter', (event) => {
const {
data, // 筛选后的数据集合
nativeEvent, // 原始 DOM 事件
} = event;
const [yMin, yMax] = data.selection[1]; // 注意数据结构差异
console.log(`数值区间:${yMin.toFixed(2)} - ${yMax.toFixed(2)}`);
});
chart.on('brush:filter', (event) => {
const {
data, // 筛选后的数据集合
nativeEvent, // 原始 DOM 事件
} = event;
const [yMin, yMax] = data.selection[1]; // 注意数据结构差异
console.log(`数值区间:${yMin.toFixed(2)} - ${yMax.toFixed(2)}`);
});
{
"call": r
}

触发交互

通过编程方式触发筛选:

chart.emit('brush:filter', {
data: {
selection: [
null, // X 轴保持全选
[20, 60], // Y 轴范围 20-60
],
},
});

案例

import { Column } from '@ant-design/plots';
import React from 'react';
import { createRoot } from 'react-dom';
const DemoColumn = () => {
const config = {
data: [
{ letter: 'A', frequency: 0.08167 },
{ letter: 'B', frequency: 0.01492 },
{ letter: 'C', frequency: 0.02782 },
{ letter: 'D', frequency: 0.04253 },
{ letter: 'E', frequency: 0.12702 },
{ letter: 'F', frequency: 0.02288 },
{ letter: 'G', frequency: 0.02015 },
{ letter: 'H', frequency: 0.06094 },
{ letter: 'I', frequency: 0.06966 },
{ letter: 'J', frequency: 0.00153 },
{ letter: 'K', frequency: 0.00772 },
{ letter: 'L', frequency: 0.04025 },
{ letter: 'M', frequency: 0.02406 },
{ letter: 'N', frequency: 0.06749 },
{ letter: 'O', frequency: 0.07507 },
{ letter: 'P', frequency: 0.01929 },
{ letter: 'Q', frequency: 0.00095 },
{ letter: 'R', frequency: 0.05987 },
{ letter: 'S', frequency: 0.06327 },
{ letter: 'T', frequency: 0.09056 },
{ letter: 'U', frequency: 0.02758 },
{ letter: 'V', frequency: 0.00978 },
{ letter: 'W', frequency: 0.0236 },
{ letter: 'X', frequency: 0.0015 },
{ letter: 'Y', frequency: 0.01974 },
{ letter: 'Z', frequency: 0.00074 },
],
autoFit: true,
interaction: {
brushYFilter: {
maskFill: '#000',
maskFillOpacity: 0.2,
maskStroke: 'red',
maskStrokeOpacity: 0.9,
maskLineWidth: 2,
maskLineDash: [4, 8],
maskOpacity: 0.2,
maskShadowColor: '#d3d3d3',
maskShadowBlur: 10,
maskShadowOffsetX: 10,
maskShadowOffsetY: 10,
maskCursor: 'pointer',
},
},
xField: 'letter',
yField: 'frequency',
};
return <Column {...config} />;
};
createRoot(document.getElementById('container')).render(<DemoColumn />);