Skip to content

Commit 605cb06

Browse files
fix(BarChart/ColumnChart): fix data labels for nested data accessors (#579)
1 parent 12e3278 commit 605cb06

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

packages/charts/src/components/BarChart/BarChart.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
XAxis,
2121
YAxis
2222
} from 'recharts';
23+
import { getValueByDataKey } from 'recharts/lib/util/ChartUtils';
2324
import { useChartMargin } from '../../hooks/useChartMargin';
2425
import { useLongestYAxisLabelBar } from '../../hooks/useLongestYAxisLabelBar';
2526
import { useObserveXAxisHeights } from '../../hooks/useObserveXAxisHeights';
@@ -40,6 +41,10 @@ const measureDefaults = {
4041
opacity: 1
4142
};
4243

44+
const valueAccessor = (attribute) => ({ payload }) => {
45+
return getValueByDataKey(payload, attribute);
46+
};
47+
4348
interface MeasureConfig extends IChartMeasure {
4449
/**
4550
* Bar Width
@@ -164,9 +169,6 @@ const BarChart: FC<BarChartProps> = forwardRef((props: BarChartProps, ref: Ref<a
164169
const [width, legendPosition] = useLongestYAxisLabelBar(dataset, dimensions);
165170
const marginChart = useChartMargin(chartConfig.margin, chartConfig.zoomingTool);
166171
const [xAxisHeight] = useObserveXAxisHeights(chartRef, 1);
167-
const valueAccessor = (attribute) => ({ payload }) => {
168-
return payload[attribute];
169-
};
170172

171173
return (
172174
<ChartContainer

packages/charts/src/components/ColumnChart/ColumnChart.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
XAxis,
2121
YAxis
2222
} from 'recharts';
23+
import { getValueByDataKey } from 'recharts/lib/util/ChartUtils';
2324
import { useChartMargin } from '../../hooks/useChartMargin';
2425
import { useLongestYAxisLabel } from '../../hooks/useLongestYAxisLabel';
2526
import { useObserveXAxisHeights } from '../../hooks/useObserveXAxisHeights';
@@ -88,6 +89,10 @@ const measureDefaults = {
8889
opacity: 1
8990
};
9091

92+
const valueAccessor = (attribute) => ({ payload }) => {
93+
return getValueByDataKey(payload, attribute);
94+
};
95+
9196
/**
9297
* <code>import { ColumnChart } from '@ui5/webcomponents-react-charts/lib/ColumnChart';</code>
9398
*/
@@ -169,9 +174,6 @@ const ColumnChart: FC<ColumnChartProps> = forwardRef((props: ColumnChartProps, r
169174

170175
const marginChart = useChartMargin(chartConfig.margin, chartConfig.zoomingTool);
171176
const xAxisHeights = useObserveXAxisHeights(chartRef, props.dimensions.length);
172-
const valueAccessor = (attribute) => ({ payload }) => {
173-
return payload[attribute];
174-
};
175177

176178
return (
177179
<ChartContainer

0 commit comments

Comments
 (0)