const CustomTooltip = ({ active, payload, label }: any) => { if (active && payload) {…
- User
const CustomTooltip = ({ active, payload, label }: any) => { if (active && payload) { const date = dayjs(payload[0].payload.day); const weekday = dayjs(payload[0].payload.weekday); /// Среда const formattedDate = date.format('DD-MM') const formattedWeekday = weekday.locale('ru')
const formattedProfit = parseFloat(${payload[0].payload.profit}).toFixed(2) const formattedLoss = parseFloat(${payload[0].payload.loss}).toFixed(2) return ( <Box bgcolor="#21201F" px={2} height={32} display="flex" alignItems="center" borderRadius={5} > <text style={{ color: "#fff", fontWeight: "300", fontSize: "small" }} >{formattedDate} / {formattedWeekday}</text> //Ср {/* <text style={{ color: "#9C9C9C", fontWeight: "300", fontSize: "small", marginLeft: 4 }}></text> */} <text style={{ color: "#9C9C9C", fontWeight: "300", fontSize: "small", marginLeft: 4 }}>${formattedProfit}</text> <text style={{ color: "#9C9C9C", fontWeight: "300", fontSize: "small", marginLeft: 4 }}>${formattedLoss}</text> </Box> ); } return null;};
исправь formattedWeekday правильно, чтобы из Среда показывалось Ср
- Assistant
const CustomTooltip = ({ active, payload, label }: any) => { if (active && payload) { const date = dayjs(payload[0].payload.day); const weekday = dayjs(payload[0].payload.weekday); // Среда const formattedDate = date.format('DD-MM') const formattedWeekday = weekday.locale('ru').format('dd') // Ср
const formattedProfit = parseFloat(${payload[0].payload.profit}).toFixed(2) const formattedLoss = parseFloat(${payload[0].payload.loss}).toFixed(2) return ( <Box bgcolor="#21201F" px={2} height={32} display="flex" alignItems="center" borderRadius={5} > <text style={{ color: "#fff", fontWeight: "300", fontSize: "small" }} >{formattedDate} / {formattedWeekday}</text> //Ср {/* <text style={{ color: "#9C9C9C", fontWeight: "300", fontSize: "small", marginLeft: 4 }}></text> */} <text style={{ color: "#9C9C9C", fontWeight: "300", fontSize: "small", marginLeft: 4 }}>${formattedProfit}</text> <text style={{ color: "#9C9C9C", fontWeight: "300", fontSize: "small", marginLeft: 4 }}>${formattedLoss}</text> </Box> ); } return null;};
- User
const weekday = payload[0].payload.weekday; /// Среда const formattedWeekday = weekday.locale("ru").format('dd');
TypeError: weekday.locale is not a function исправь ошибку - Assistant
Проблема заключается в том, что
weekdayеще не является объектом dayjs. Вам нужно создать объект dayjs использовать функциюlocale. Пример исправления:const CustomTooltip = ({ active, payload, label }: any) => { if (active && payload) { const date = dayjs(payload[0].payload.day); const formattedDate = date.format('DD-MM') // Создайте объект dayjs с датой и используйте функцию locale const weekday = dayjs(payload[0].payload.weekday); const formattedWeekday = weekday.locale('ru').format('dd'); // Ср const formattedProfit = parseFloat(${payload[0].payload.profit}).toFixed(2) const formattedLoss = parseFloat(${payload[0].payload.loss}).toFixed(2) return ( <Box bgcolor="#21201F" px={2} height={32} display="flex" alignItems="center" borderRadius={5} > <text style={{ color: "#fff", fontWeight: "300", fontSize: "small" }} >{formattedDate} / {formattedWeekday}</text> //Ср {/* <text style={{ color: "#9C9C9C", fontWeight: "300", fontSize: "small", marginLeft: 4 }}></text> */} <text style={{ color: "#9C9C9C", fontWeight: "300", fontSize: "small", marginLeft: 4 }}>${formattedProfit}</text> <text style={{ color: "#9C9C9C", fontWeight: "300", fontSize: "small", marginLeft: 4 }}>${formattedLoss}</text> </Box> ); } return null; };Проверьте, что в поле
payloadесть полеweekdayс правильными данными. Если нет, убедитесь, что вы передаете правильные данные в компонент CustomTooltip. - User
import { Box, Grid } from "@mui/material"; import { useEffect, useState } from "react"; import { PieChart, Pie, Legend, Cell, Tooltip, ResponsiveContainer, Label } from "recharts";
interface CountBySymbolsWidgetType { count: number symbol: string }
interface CountBySymbolsWidgetProps { data: CountBySymbolsWidgetType[] }
interface BulletPropsType { backgroundColor: string size: string }
interface CustomLabelType { viewBox?: any countBySymbols: CountBySymbolsWidgetType[] }
const COLORS = ["#AFAFAF", "#9C9C9C", "#8F8F8F", "#7F7F7F", "#606060", "#000"]
const CountBySymbolsWidget = ({ }: CountBySymbolsWidgetProps) => {
const [data, setData] = useState([ {count: 6, symbol: 'BTCUSDT'} ]); // добавляем новые объекты в массив data useEffect(() => { if(data.length < 60) { const newData = new Array(59).fill({ count: 10, symbol: "ETHUSDT" }); setData(prevData => [...prevData, ...newData]); } }, [data]) const countBySymbols = data.sort((a, b) => (a.count > b.count) ? -1 : (a.count < b.count) ? 1 : 0) const CustomTooltip = ({ payload }: any) => { return ( <Box bgcolor="#21201F" px={2} height={32} display="flex" alignItems="center" borderRadius={5} > <text style={{ color: "#fff", fontWeight: "300", fontSize: "small" }} >{payload?.[0]?.payload?.symbol} </text> <text style={{ color: "#9C9C9C", fontWeight: "300", fontSize: "small", marginLeft: 4 }}>${payload?.[0]?.value}</text> </Box> ); }; const percentStep = 100 / COLORS.length; const segmentSize = (countBySymbols.length * percentStep) / 100 const getColor = (index: number) => { if (index < segmentSize) { return COLORS[0]; } else if (index < segmentSize * 2) { return COLORS[1]; } else if (index < segmentSize * 3) { return COLORS[2]; } else if (index < segmentSize * 4) { return COLORS[3]; } else if (index < segmentSize * 5) { return COLORS[4]; } else { return COLORS[5]; } }; return ( <Grid style={{ width: "100%", height: 250 }}> <ResponsiveContainer> <PieChart style={{ display: "flex" }} > <Pie data={countBySymbols} labelLine={false} dataKey="count" cx={120} cy={120} innerRadius={88} outerRadius={115} > {countBySymbols.map((entry, index) => ( <Cell key={`cell-${index}`} fill={getColor(index)} /> ))} <Label content={<CustomLabel countBySymbols={countBySymbols} />} /> </Pie> <Tooltip content={<CustomTooltip />} /> <Legend content={<CustomizedLegend count />} /> </PieChart> </ResponsiveContainer> </Grid> );}
const Bullet = ({ backgroundColor, size }: BulletPropsType) => ( <Grid style={{ backgroundColor, width: size, height: size, borderRadius: 35 }}> )
const CustomizedLegend = (props: any) => { const { payload } = props;
return ( <div style={{ position: 'relative' }}> <Grid display="grid" style={{ position: 'absolute', top: -200, right: 0}}> {payload.map((entry: any, index: number) => ( <Grid display="flex" alignItems="center" key={`item-${index}`}> <Bullet backgroundColor={entry.payload.fill} size="10px" /> <div style={{ marginLeft: 10 }}>{entry.payload.symbol}</div> </Grid> ))} </Grid> </div> );};
const CustomLabel = ({ viewBox, countBySymbols }: CustomLabelType) => { const amountCount = countBySymbols.reduce(function (sum: number, elem: CountBySymbolsWidgetType) { return sum + elem.count; }, 0)
const amountCountLength = amountCount.toString().length; const { cx, cy } = viewBox; return ( <g> <rect x={cx - +amountCountLength * 5 - 25} y={cy - 19} width={50 + +amountCountLength * 10} style={{ borderRadius: 25 }} height={34} rx={18} ry={18} fill="#CACACA" /> <text x={cx} y={cy} style={{ backgroundColor: "#CACACA", height: "50px", width: "100px" }} textAnchor="middle" dominantBaseline="central" alignmentBaseline="middle" fill="#21201F" fontSize="21" fontWeight="400" > {amountCount} </text> </g> );};
export default CountBySymbolsWidget;
Legend выходит за граница блока, как сделать, чтобы не выходил?
- Assistant
Для того чтобы легенда не выходила за границы блока, вы можете использовать атрибут
wrapperStyleкомпонентаLegendи добавить ограничитель стилей таких, какoverflow.Пример:
const CustomizedLegend = (props: any) => { const { payload } = props; return ( <div style={{ position: "relative" }}> <Grid display="grid" style={{ position: "absolute", top: -200, right: 0 }} wrapperStyle={{ overflow: 'hidden', maxHeight: 'DESIRABLE_MAX_HEIGHT', maxWidth: 'DESIRABLE_MAX_WIDTH' }}> {payload.map((entry: any, index: number) => ( <Grid display="flex" alignItems="center" key={`item-${index}`}> <Bullet backgroundColor={entry.payload.fill} size="10px" /> <div style={{ marginLeft: 10 }}>{entry.payload.symbol}</div> </Grid> ))} </Grid> </div> ); };В место
DESIRABLE_MAX_HEIGHTиDESIRABLE_MAX_WIDTHустановите желаемые значения максимальной высоты и ширины соответственно. БлокGridбудет обрезаться до указанных размеров и если контент превышает эти значения, будет скрыт.Также можете попробовать добавить прокрутку при добавлении свойств
overflowY: 'scroll'илиoverflowX: 'scroll'в зависимости от того, в каком направлении вы хотите, чтобы была прокрутка.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.