Add different colors to 4 quadrants in Plot #3054
Unanswered
sarthakag-veritech
asked this question in
Q&A
Replies: 1 comment
-
如何为 Ant Design Charts 的散点图添加四象限区域背景色 你的需求是:使用 标准实现步骤
标准代码示例(文档写法)import React from "react";
import { Scatter } from "@ant-design/charts"; // 注意:建议用 "@ant-design/charts",v2.4.0推荐(@ant-design/plots基本兼容)
const data = [
{ x: 10, y: 20 },
{ x: 30, y: 60 },
{ x: 70, y: 40 },
{ x: 90, y: 80 },
];
const config = {
data,
xField: "x",
yField: "y",
pointSize: 5,
quadrant: {
xBaseline: 50, // x 轴分割线
yBaseline: 50, // y 轴分割线
lineStyle: {
stroke: "#aaa",
lineDash: [4, 4],
},
labels: [
{ content: "Q1", position: "top-right" },
{ content: "Q2", position: "top-left" },
{ content: "Q3", position: "bottom-left" },
{ content: "Q4", position: "bottom-right" },
],
},
// 四个象限区域填色
annotations: [
// Q1: 右上
{
type: "region",
start: [50, 50],
end: ["max", "max"],
style: {
fill: "rgba(118, 96, 243, 0.1)",
stroke: null,
},
},
// Q2: 左上
{
type: "region",
start: ["min", 50],
end: [50, "max"],
style: {
fill: "rgba(243, 112, 176, 0.1)",
stroke: null,
},
},
// Q3: 左下
{
type: "region",
start: ["min", "min"],
end: [50, 50],
style: {
fill: "rgba(49, 199, 174, 0.1)",
stroke: null,
},
},
// Q4: 右下
{
type: "region",
start: [50, "min"],
end: ["max", 50],
style: {
fill: "rgba(255, 200, 0, 0.1)",
stroke: null,
},
},
],
};
export default () => <Scatter {...config} />; 参数说明
常见问题/注意事项
官方文档参考如果你还有其他定制化需求、或 region 注解不生效,请补充你的“组件版本号、报错信息”等详细场景,我会帮你进一步定位。 此回答由AI自动生成,仅供参考。如有疑问,请等待维护者回复。 |
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.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey, I want to add different colors to 4 quadrants of a plot in antd
I am trying type region its not working
Attaching an reference image

Beta Was this translation helpful? Give feedback.
All reactions