xAxis overlapping with chart legend

See original GitHub issue

The issue is very difficult to reproduce in jsfiddle, so instead I will post some snippets and screenshot.

The chart legend is overlapping with the xAxis labels: Screen Shot 2021-02-16 at 12 02 43 AM

And on hovering over the chart, the chart height re-adjusts and corrects itself. I am using Recharts version 1.8.5

Below is the structure of my chart:

<div style={{ width: '100%', height: customHeight }}>
	{
		config.title
		&& (
			<Title title={config.title} />
		)
	}
	{
		allowZoom
		&& (
			<ZoomButtons
				props={props}
			/>
		)
	}
	<ResponsiveContainer>
		<LineChart
			data={dataToPlot()}
			margin={{
				right: 25,
				left: showYLabel ? 0 : leftMargin,
				top: CHART_MARGIN_TOP,
				bottom: 10,
			}}
			onMouseDown={(e) => {
				// some logic
			}}
			onMouseUp={() => {
				// some logic
			}}
			onMouseEnter={() => {
				// some logic
			}}
			onMouseMove={(e) => {
				// some logic
			}}
			onMouseLeave={() => {
				// some logic
			}}
		>
			<XAxis
				{...commonXAxisConfigs}
			/>
			<YAxis
				{...commonYAxisConfigs}
			/>
			{renderTooltip()}
			{
				!config.hideLegends
					? (
						<Legend
							wrapperStyle={{
								paddingTop: 20,
							}}
							content={(
								<CustomLegend
									props={props}
								/>
							)}
						/>
					)
					: null
			}

			{renderLines()}
		</LineChart>
	</ResponsiveContainer>
</div>

Any idea what could be going wrong? Again sorry for not being able to post a jsfiddle link as it’s only happening while fetching the data from server. Difficult to reproduce with hardcoded data.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
Yeshwanthicommented, Feb 25, 2021

Also this worked for me. Setting the legend wrapper style property. I am using recharts version 2.0.6. wrapperStyle={{ position: 'relative' }}

2reactions
quandaicacommented, Sep 19, 2021

I’m facing this issue on the latest version v2.1.1. image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Highcharts Legend Overlaps with X-Axis - Stack Overflow
I'm setting up a chart where the legend is located below the line graph. For some reason, the legend seems to overlap with...
Read more >
MS Excel axis labels overlap in charts (what can you do ...
Stop Labels overlapping chart. There is a really quick fix for this. As shown below: Right click on the Axis; Choose the Format...
Read more >
Overlapping Bar Chart X-Axis Labels - Ignition Early Access
Makes sense. A better way to do this might be to give each column its own color that references the legend, where the...
Read more >
Categories overlapping on xAxis legend - Highcharts
I've got an issue with categories and xAxis title. ... Do you have any trick to update chart's height, regarding categories string size...
Read more >
Resolve Overlapping Labels in X-Axis and bind to View Model ...
How can i Resolve this? Antoher Problem is that i want to have a Checkbox in the Legend to Show or Hide Specific...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found