Add a randomly generated gradientID to so each chart has a unique gradient

This commit is contained in:
Alex Holliday
2024-11-19 13:54:51 +08:00
parent e3c13d93ec
commit 9cf2be774b
2 changed files with 4 additions and 2 deletions
@@ -85,6 +85,7 @@ const CustomAreaChart = ({
customTooltip,
}) => {
const theme = useTheme();
const gradientId = `gradient-${Math.random().toString(36).slice(2, 9)}`;
return (
<ResponsiveContainer
width="100%"
@@ -101,6 +102,7 @@ const CustomAreaChart = ({
/>
{gradient === true &&
createGradient({
id: gradientId,
startColor: gradientStartColor,
endColor: gradientEndColor,
direction: gradientDirection,
@@ -116,7 +118,7 @@ const CustomAreaChart = ({
type="monotone"
dataKey={dataKey}
stroke={strokeColor}
fill={gradient === true ? "url(#colorUv)" : fillColor}
fill={gradient === true ? `url(#${gradientId})` : fillColor}
/>
{customTooltip ? (
@@ -17,7 +17,7 @@
*/
export const createGradient = ({
id = "colorUv",
id,
startColor,
endColor,
startOpacity = 0.8,