-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
79 lines (74 loc) · 1.83 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import styles from "./BarChart.module.css";
import {
BarChart as ReBarChart,
Bar,
XAxis,
YAxis,
ResponsiveContainer,
CartesianGrid,
Tooltip,
} from "recharts";
import type { Properties } from "../../types";
import { toUSD, toUpperFirst, abbrNumber } from "../../utils";
interface Props {
data: Properties;
labelX: string;
labelY: string;
}
const CustomTooltip = ({ active, payload, label }: any) => {
if (active && payload && payload.length) {
return (
<div className={styles.container}>
<p className={styles.label}>{`${toUpperFirst(label)}`}</p>
<p className={styles.value}>{toUSD(payload[0].value)}</p>
</div>
);
}
return null;
};
export default function BarChart(props: Props) {
const { data, labelX, labelY } = props;
return (
<ResponsiveContainer width="100%" height="100%">
<ReBarChart
data={data}
margin={{
top: 5,
right: 30,
left: 25,
bottom: 35,
}}
>
<XAxis
dataKey={labelX}
label={{
value: toUpperFirst(labelX),
position: "insideBottom",
offset: -15,
style: {
fontSize: "1.2rem",
fontWeight: "bold",
},
}}
/>
<YAxis
dataKey={labelY}
label={{
value: toUpperFirst(labelY),
angle: -90,
position: "insideLeft",
offset: -10,
style: {
fontSize: "1.2rem",
fontWeight: "bold",
},
}}
tickFormatter={(value) => `$${abbrNumber(value)}`}
/>
<Tooltip content={<CustomTooltip />} />
<CartesianGrid strokeDasharray="3 3" />
<Bar dataKey="value" fill="#91C483" />
</ReBarChart>
</ResponsiveContainer>
);
}