Reference line text in Scatter Plot #3050
Unanswered
sarthakag-veritech
asked this question in
Q&A
Replies: 2 comments 1 reply
-
在参考线(Reference Line)上方添加文本,以及图表交互缩放复原方法 1. 在参考线上方添加文本您可以通过 annotations 属性,为参考线添加说明文字。 步骤说明
标准代码示例import { Scatter } from '@ant-design/plots';
import React from 'react';
import { createRoot } from 'react-dom';
const DemoScatter = () => {
const config = {
data: {
type: 'fetch',
value: 'https://gw.alipayobjects.com/os/antvdemo/assets/data/bubble.json',
},
xField: 'GDP',
yField: 'LifeExpectancy',
sizeField: 'Population',
colorField: 'continent',
shapeField: 'point',
scale: {
size: { type: 'log', range: [4, 20] },
},
style: { fillOpacity: 0.3, lineWidth: 1 },
annotations: [
{
// 横向参考线
type: "lineY",
data: [70],
style: {
stroke: "#FF9066",
lineWidth: 2,
lineDash: [4, 4],
},
},
{
// 对应的文本注解(显示在 Y=70 参考线上方)
type: "text",
position: ['min', 70], // 'min' 代表最左侧,70为Y坐标
content: "寿命参考线 (70)",
style: {
fill: "#FF9066",
fontSize: 14,
fontWeight: "bold",
},
offsetY: -10, // 控制文本与参考线间距,上方
},
{
// 纵向参考线
type: "lineX",
data: [40000],
style: {
stroke: "#FF9066",
lineWidth: 2,
lineDash: [4, 4],
},
},
{
// 对应的文本注解(显示在 X=40000 参考线上方)
type: "text",
position: [40000, 'max'], // X=40000,Y为最大处
content: "GDP参考线 (40000)",
style: {
fill: "#FF9066",
fontSize: 14,
fontWeight: "bold",
},
offsetX: 10, // 适当调整
offsetY: -10, // 适当调整
},
],
};
return <Scatter {...config} />;
};
createRoot(document.getElementById('container')).render(<DemoScatter />); 参数说明
2. 缩放后如何缩放回去?操作方法
标准配置/用法const config = {
// ... 你的其他配置
interactions: [
{ type: 'brush' },
{ type: 'zoom' }, // 支持缩放与拖拽
],
}; 缩放复原方法:
3. 相关文档链接如需更多自定义,欢迎补充具体需求! 此回答由AI自动生成,仅供参考。如有疑问,请等待维护者回复。 |
Beta Was this translation helpful? Give feedback.
1 reply
-
No, your provided suggestions are not working, additionally reference urls are not working |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I want to add a text above my reference line in below plot.
Reference image attached
Also after adding interactivity I am able to zoom on my bubbles, but how do I zoom out back?
Beta Was this translation helpful? Give feedback.
All reactions