import React, {useEffect, useState} from "react"; import {Box, Grid, Typography,…
- User
import React, {useEffect, useState} from "react"; import {Box, Grid, Typography, useTheme} from "@mui/material"; import {XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, ComposedChart, Bar} from "recharts"; import {updateDiaryWidget, Widget} from "../../../actions/cicap-diary-widgets"; import {useAuthContext} from "../../AuthProvider/AuthProvider";
interface ProfitWeekdaysChartProps { data: number[]; widget: Widget; onWidgetUpdate: (id: string) => void; }
const ProfitWeekdaysChart = ({data, widget, onWidgetUpdate}: ProfitWeekdaysChartProps) => { return ( <> { periodProfitWeekdaysChart.map((p, i) => <Typography onClick={(e) => { //@ts-ignore onChangePeriodProfitWeekdaysChart(e.target.outerText); }} fontSize={13} sx={{ cursor: "pointer", mr: ".25rem", display: "flex", flexWrap: "wrap", justifyContent: "center", alignContent: "center", height: "24px", padding: "2px 10px 1px", backgroundColor: !p.checked ? !darkTheme ? "#E6E6E6" : "#242424" : !darkTheme ? "#C3463B" : "#B41C18", color: !p.checked ? !darkTheme ? "rgba(91, 91, 91, 0.6)" : "#999999" : "#fff", borderRadius: "1rem", }}> {p.title} ) } <ComposedChart data={formattedSeriesData} layout="vertical" margin={{ top: 30, right: 20, bottom: 20, left: -25, }} > <CartesianGrid horizontal={false} strokeDasharray="3 3" stroke={darkTheme ? "#5c5a57" : "#ccc"} /> <YAxis dataKey="name" interval={0} axisLine={darkTheme ? false : {stroke: "#EBEBEB"}} tickLine={false} fontSize="12" type="category" scale="band" tick={({x, y, payload, width}) => { return ( <text x={x - 10} y={y + 10} textAnchor="middle" fill="#9E9B98" fontSize={13} > {payload.value} ); }} /> <XAxis type="number" axisLine={false} tickLine={false} tick={({x, y, payload}) => { return ( <text x={x} y={y + 10} textAnchor="middle" fill="#9E9B98" fontSize={13} > { +payload.value >= 0 ?
$${Math.abs(+payload.value)}:-$${Math.abs(+payload.value)}} ); }} /> <Tooltip content={} /> <Bar dataKey="profit" radius={[0, 8, 8, 0]} barSize={60} fill={darkTheme ? "#0F3B2B" : "#F3C9CE"} /> </> ); };нужно сделть высота баров по оси x высотой в 24px, цвет баров в темной теме, если value отрицательный, то #0F3B2B, если положительный то #89ADA0. Так же сделать чтобы при наедении мышко
- Assistant
- User
No overload matches this call. Overload 1 of 2, '(props: Props | Readonly): Bar', gave the following error. Type '(data: any) => "#0F3B2B" | "#F3C9CE" | "#89ADA0"' is not assignable to type 'string'. Overload 2 of 2, '(props: Props, context: any): Bar', gave the following error. Type '(data: any) => "#0F3B2B" | "#F3C9CE" | "#89ADA0"' is not assignable to type 'string'.ts(2769) ProfitWeekdaysChartWidget.tsx(188, 18): Did you mean to call this expression? ProfitWeekdaysChartWidget.tsx(188, 18): Did you mean to call this expression? Parameter 'data' implicitly has an 'any' type.ts(7006) (parameter) data: any fill={(data) => data.value < 0 ? darkTheme ? "#0F3B2B" : "#F3C9CE" : darkTheme ? "#89ADA0" : "#89ADA0"}>
- Assistant
I apologize for the confusion. It seems that there was a syntax error in my previous response.
To fix the issue, please change the following line of code:
fill={(data) => data.value < 0 ? darkTheme ? "#0F3B2B" : "#F3C9CE" : darkTheme ? "#89ADA0" : "#89ADA0"}>to:
fill={(data: any) => data.value < 0 ? (darkTheme ? "#0F3B2B" : "#F3C9CE") : (darkTheme ? "#89ADA0" : "#89ADA0")}>This will ensure that the fill prop receives a string value instead of a function. Additionally, I have added parentheses to group the conditions for better readability.
I apologize for any inconvenience caused.
- User
нужно добавить чтобы при наведении на бар он становился желтым
- Assistant
To change the color of the bar when hovering over it, you can use the "onMouseEnter" and "onMouseLeave" events provided by Recharts.
- First, import the
useStatehook from React:
import React, { useState } from "react"; - First, import the
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.