Skip to content

Commit fd07365

Browse files
committed
format y-scale ticks as percentage and show less ticks
1 parent 7fa34a9 commit fd07365

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/components/graphs/DistributionBarChart.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ const DistributionBarChart = ({
2323
const [containerWidth, setContainerWidth] = useState(800);
2424
const { t } = useTranslation();
2525

26+
const formatTickAsPercentage = (value: number) => {
27+
return `${(value * 100).toFixed(1)}%`;
28+
};
29+
2630
useEffect(() => {
2731
const plotWidth = containerWidth - margin.left - margin.right;
2832
const plotHeight = height - margin.top - margin.bottom;
@@ -146,7 +150,12 @@ const DistributionBarChart = ({
146150
.attr('dx', '-.8em')
147151
.attr('dy', '.15em');
148152

149-
svg.append('g').call(d3.axisLeft(yScale));
153+
svg.append('g').call(
154+
d3
155+
.axisLeft(yScale)
156+
.ticks(5) // Reduce number of ticks
157+
.tickFormat(d => formatTickAsPercentage(d as number))
158+
);
150159

151160
// Add title
152161
svg.append('text')

0 commit comments

Comments
 (0)