Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If I set true to YAxisProps['reversed'], The YAxis minimum value is not displayed #2175

Closed
taqm opened this issue Jun 21, 2020 · 3 comments
Closed

Comments

@taqm
Copy link

taqm commented Jun 21, 2020

If I set true to YAxisProps['reversed'], The YAxis minimum value is not displayed.

The graph on the right does not show 0 on the y-axis

スクリーンショット 2020-06-21 18 50 15

Is this what intended? And, How do I display value?

(XAxis have the same problem.

Example

https://codesandbox.io/s/recharts-playground-8t6bg

@xile611
Copy link
Member

xile611 commented Dec 21, 2020

Sorry for not handling your issue in time, please try the latest version. If the problem persists, please open a new issue according to the issue guide.

@xile611 xile611 closed this as completed Dec 21, 2020
@vincent-kradev
Copy link

vincent-kradev commented Feb 11, 2024

encountered this bug, in v2.11.0 . any workarounds or fixes??

@Dib5pm
Copy link

Dib5pm commented Apr 26, 2024

Solution

This will fix this issue when using the reversed prop on the YAxis. If you notice that the axes are getting cut off or not displaying fully, you can add some margins to the chart to fix this. Here’s how you can set it up:

margin={{
  top: 10,
  right: 30,
  left: 0,
  bottom: 0,
}}

Full example

import React, { PureComponent } from 'react';
import { BarChart, Bar, Rectangle, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts';

const data = [
  {
    name: 'Page A',
    uv: 4000,
    pv: 2400,
    amt: 2400,
  },
  {
    name: 'Page B',
    uv: 3000,
    pv: 1398,
    amt: 2210,
  },
  {
    name: 'Page C',
    uv: 2000,
    pv: 9800,
    amt: 2290,
  },
  {
    name: 'Page D',
    uv: 2780,
    pv: 3908,
    amt: 2000,
  },
  {
    name: 'Page E',
    uv: 1890,
    pv: 4800,
    amt: 2181,
  },
  {
    name: 'Page F',
    uv: 2390,
    pv: 3800,
    amt: 2500,
  },
  {
    name: 'Page G',
    uv: 3490,
    pv: 4300,
    amt: 2100,
  },
];

export default class Example extends PureComponent {
  static demoUrl = 'https://codesandbox.io/s/simple-bar-chart-tpz8r';

  render() {
    return (
      <ResponsiveContainer width="100%" height="100%">
        <BarChart
          width={500}
          height={300}
          data={data}
          margin={{
            top: 10,
            right: 30,
            left: 0,
            bottom: 0,
          }}
        >
          <CartesianGrid strokeDasharray="3 3" />
          <XAxis dataKey="name" />
          <YAxis reversed={true} />
          <Tooltip />
          <Legend />
          <Bar dataKey="pv" fill="#8884d8" activeBar={<Rectangle fill="pink" stroke="blue" />} />
          <Bar dataKey="uv" fill="#82ca9d" activeBar={<Rectangle fill="gold" stroke="purple" />} />
        </BarChart>
      </ResponsiveContainer>
    );
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants