question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Left and right padding on CartesianGrid on ComposedChart

See original GitHub issue

Hi everyone. I’m currently experiencing a weird margin on my CartesianGrid relative to my ComposedChart.

luft

I’ve tried using margin={{left: -20, right: -20}} on all my components, but nothing seems to remove it.

This is my component:

     <ResponsiveContainer 
        className={this.props.className} 
        width="100%" 
        height={210}
      >
        <ComposedChart data={projectedData}>
          <XAxis 
            dataKey="name"
            padding={{ left: 0, right: 0 }}
            tickLine={false}
            axisLine={false}
            tick={{fontSize: '10px', marginTop: "8px"}}
            minTickGap={64}
          />
          <YAxis
            dataKey="projected"
            padding={{ left: 0, right: 0 }}
            tickLine={false}
            axisLine={false}
            tick={{fontSize: '10px'}}
            tickFormatter={(tick) => ((tick / 1000) + 'k')}
            minTickGap={50}
          />
          <CartesianGrid strokeDasharray="2 2" strokeWidth="0.5" stroke="white" />

          <Bar dataKey="realized" stackId="a" fill="transparent" />
          <Bar dataKey="diffToProjected" stackId="a" maxBarSize={8} />
          <Line type="linear" dataKey="projected" stroke="white" dot={false} />
          <Line type="linear" dataKey="realized" stroke="#263465" dot={false} />
        </ComposedChart>
      </ResponsiveContainer>

Any tips on how to remove this left/right margin?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:16
  • Comments:14

github_iconTop GitHub Comments

28reactions
seryozhatebecommented, Jun 6, 2019

scale = point for XAxis, works for me! <XAxis dataKey="name" scale="point" />

1reaction
noxalexcommented, Apr 23, 2019

On XAxis and YAxis you can use prop tick={{ dx: -25 }} dx to move labels by X axis and dy to move labels by Y axis, example:

<YAxis type=“number” ticks={[0, 25, 50, 75]} tickCount={4} tickSize={0} axisLine={false} tick={{ dx: -25 }} />

Read more comments on GitHub >

github_iconTop Results From Across the Web

Recharts When Using ComposedChart Bar is over YAxis
Use the XAxis padding prop like this: <XAxis dataKey="name" padding={{ left: 20, right: 20 }} />.
Read more >
Build and Custom Style Recharts Data Charts
Recharts has standard charts and tooltips, but customizing them takes extra effort.
Read more >
AreaChart | Recharts
Recharts - Re-designed charting library built with React and D3.
Read more >
recharts.online
< recharts /> online. 1. Pick chart type. Sample data is provided. ComposedChart. AreaChart. BarChart. LineChart. ComposedChart. PieChart. RadarChart.
Read more >
recharts Legend JavaScript Examples - ProgramCreek.com
... data={districtTrendData} margin={{top: 10, right: 30, left: 0, bottom: 0}}> <CartesianGrid ... <ComposedChart data={data} syncId="syncA"> <CartesianGrid ...
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