diff --git a/projects/js-packages/charts/src/components/line-chart/line-chart.tsx b/projects/js-packages/charts/src/components/line-chart/line-chart.tsx
index 1ff267c587fb9..a1ddfe4803361 100644
--- a/projects/js-packages/charts/src/components/line-chart/line-chart.tsx
+++ b/projects/js-packages/charts/src/components/line-chart/line-chart.tsx
@@ -12,6 +12,7 @@ import {
useChartDataTransform,
useChartMargin,
useElementHeight,
+ useLegendLayout,
} from '../../hooks';
import {
GlobalChartsProvider,
@@ -21,6 +22,7 @@ import {
useGlobalChartsContext,
useGlobalChartsTheme,
} from '../../providers';
+import containerStyles from '../../styles/chart-container.module.scss';
import { attachSubComponents } from '../../utils';
import { Legend, useChartLegendItems } from '../legend';
import { DefaultGlyph } from '../private/default-glyph';
@@ -379,6 +381,15 @@ const LineChartInternal = forwardRef< SingleChartRef, LineChartProps >(
const defaultMargin = useChartMargin( height, chartOptions, dataSorted, theme );
+ // Use the legend layout hook for consistent calculations
+ const { adjustedChartHeight, adjustedMargin, containerClassName } = useLegendLayout( {
+ height,
+ showLegend,
+ legendPosition,
+ legendHeight,
+ defaultMargin: { ...defaultMargin, ...margin },
+ } );
+
const error = validateData( dataSorted );
const isDataValid = ! error;
@@ -433,17 +444,21 @@ const LineChartInternal = forwardRef< SingleChartRef, LineChartProps >(
chartId,
chartRef: internalChartRef,
chartWidth: width,
- chartHeight: height - ( showLegend ? legendHeight : 0 ),
+ chartHeight: adjustedChartHeight,
} }
>
@@ -459,14 +474,8 @@ const LineChartInternal = forwardRef< SingleChartRef, LineChartProps >(
(
{ allSeriesHidden ? (
@@ -231,16 +243,12 @@ const PieChartInternal = ( {
);
}
- const width = size;
- const height = size;
- const adjustedHeight = showLegend && legendPosition === 'top' ? height - legendHeight : height;
-
// Calculate radius based on width/height
- const radius = Math.min( width, adjustedHeight ) / 2;
+ const radius = Math.min( width, adjustedChartHeight ) / 2;
// Center the chart in the available space
const centerX = width / 2;
- const centerY = adjustedHeight / 2;
+ const centerY = adjustedChartHeight / 2;
// Calculate the angle between each (use original data length for consistent spacing)
const padAngle = gapScale * ( ( 2 * Math.PI ) / data.length );
@@ -273,22 +281,24 @@ const PieChartInternal = ( {
value={ {
chartId,
chartWidth: width,
- chartHeight: adjustedHeight,
+ chartHeight: adjustedChartHeight,
} }
>