Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧐[问题]自定义颜色无效呢color #2735

Open
llp251 opened this issue Oct 15, 2024 · 0 comments
Open

🧐[问题]自定义颜色无效呢color #2735

llp251 opened this issue Oct 15, 2024 · 0 comments

Comments

@llp251
Copy link

llp251 commented Oct 15, 2024

🧐 问题描述 [详细地描述问题,让大家都能理解]

求助
我自定义了图表的color,但是无效

💻 示例代码 [如果有必要,展示代码,线上示例,或仓库]

const config = {
appendPadding: 10,
data: data,
angleField: 'value',
colorField: 'type',
radius: 0.9,
innerRadius: 0.6,
color: ['#FBBC05', '#666', '#eee'],
// legend: false, // This line hides the legend
// color: ({ type }: { type: string }) => {
// console.log('type', type);
// if (type === '1') return '#FBBC05'; // Your desired color for type '1'
// if (type === '2') return '#666'; // Your desired color for type '2'
// if (type === '0') return '#eee'; // Your desired color for type '0'
// return '#000'; // Default color if none of the above match
// },
// tooltip: false, // Disables the tooltip
tooltip: {
customContent: (_: string, items: any) => {
if (items && items.length > 0) {
const new_items = items[0];
if (new_items.name !== '0') {
if (new_items.name === '1') {
//達成率
return <div style="padding:10px">達成率: <span style="padding-left:5px">${new_items.value}</span>%</div>;
} else {
// 達成基準値
return <div style="padding:10px">達成基準値: <span style="padding-left:5px">${common_reference_rate}</span>%</div>;
}
}
}
return '';
},
},
statistic: {
visible: true,
title: {
style: {
color: '#000',
fontSize: '14px',
lineHeight: '14px',
fontWeight: '700',
textAlign: 'center',
transform: 'translate(-50%, -50%)',
},
customHtml: () => {
let subText;
if (data[0].value >= common_reference_rate) {
subText = <div style="display: inline-block;"><div style="padding:5px 0px 6px;background: #FBBC05;border-radius: 6px;color: white;width: 48px;">達成</div></div>;
} else {
subText = <div style="display: inline-block;"><div style="padding:5px 0px 6px;background: #999;border-radius: 6px;color: white;width: 48px;">未達</div></div>;
}
const conents = <div><div style="margin-top: 16px;margin-bottom: 10px;"><font style="font-size: 40px;">${data[0].value}</font>%</div>${subText}</div>;
return conents;
},
},
content: {
style: {
fontSize: '14px',
textAlign: 'center',
},
customHtml: () => ``,
},
},
};

return (
<div style={{ width: '300px', height: '300px' }}>
<Pie {...config} />

);

版本号:
"@ant-design/charts": "^2.2.1",
"antd": "^5.21.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"node":"18.12.0"

🚑 其他信息 [如截图等其他信息可以贴在这里]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant