Skip to content

Commit

Permalink
add white labels
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriele Granello committed Jan 10, 2025
1 parent 8789ec9 commit 0f5f5ef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 12 additions & 4 deletions app/components/graphs/TenureComparisonBarChart.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";

import { Bar, BarChart, CartesianGrid, XAxis } from "recharts";
import React from "react";
import { Bar, BarChart, CartesianGrid, XAxis, LabelList } from "recharts";
import { Card, CardContent, CardHeader } from "@/components/ui/card";
import {
ChartConfig,
Expand All @@ -10,6 +11,7 @@ import {
ChartTooltip,
ChartTooltipContent,
} from "@/components/ui/chart";
import { formatValue } from "@/app/lib/format";

const chartConfig = {
freehold: {
Expand All @@ -22,8 +24,6 @@ const chartConfig = {
},
} satisfies ChartConfig;

import React from "react";

// Define type for DataInput
type DataInput = {
category: string;
Expand Down Expand Up @@ -99,7 +99,15 @@ const TenureComparisonBarChart: React.FC<StackedBarChartProps> = ({ data }) => {
/>
<ChartTooltip content={<ChartTooltipContent hideLabel />} />
<ChartLegend content={<ChartLegendContent />} />
<Bar dataKey="monthly" strokeWidth={2} activeIndex={2} />
<Bar dataKey="monthly" strokeWidth={2} activeIndex={2}>
<LabelList
dataKey="monthly"
position="center"
formatter={formatValue}
fill="white"
fontSize={12}
/>
</Bar>
</BarChart>
</ChartContainer>
</CardContent>
Expand Down
4 changes: 2 additions & 2 deletions app/lib/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export const formatValue = (value: number) => {
if (value >= 1000000) {
return ${(value / 1000000).toFixed(1)}M`;
}
if (value >= 1000) {
if (value >= 10000) {
return ${(value / 1000).toFixed(0)}K`;
}
return ${value}`;
return ${value.toFixed(0)}`;
};

0 comments on commit 0f5f5ef

Please sign in to comment.