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

Allow X/YAxis to start be anchored to a certain value like ReferenceLine #4321

Open
1 task done
albert-kp opened this issue Mar 20, 2024 · 6 comments
Open
1 task done
Labels
enhancement Enhancement to a current API feature request Issues that are feature requests

Comments

@albert-kp
Copy link

albert-kp commented Mar 20, 2024

  • I have searched the issues of this repository and believe that this is not a duplicate.

Reproduction link

https://stackblitz.com/edit/vitejs-vite-gmc1wp?file=README.md

Steps to reproduce

  1. Provide Chart data having positive and negative values for y axis.
  2. The rendered chart should plot the x-axis correctly.

What is expected?

The xaxis orientation should be always at 0 of yaxis

What is actually happening?

The xaxis orientation is now at bottom with minValue of yaxis.
image

Environment Info
Recharts v2.12.3
React 18.2.0
System Windows 11
Browser Microsoft Edge Version 122.0.2365.92 (Official build) (64-bit)
@albert-kp albert-kp changed the title Xaxis Line should start at 0 posiition in yaxis for charts with positive and negative values Xaxis Line should start at 0 position in yaxis for charts with positive and negative values Mar 20, 2024
@ckifer
Copy link
Member

ckifer commented Mar 20, 2024

Hmm.. I don't think it's right to say that the X axis should always be at 0. In fact, I think most of the time with negative values it should stay at the bottom of the chart like it is. The axis would end up getting in the way and the labels would be hard to read.

Take another charting library for example https://www.highcharts.com/demo/highcharts/column-negative

Can you give a mockup of what you want? I'm not sure it's going to look good with the axis and its labels in the middle of the chart

@albert-kp
Copy link
Author

Hmm.. I don't think it's right to say that the X axis should always be at 0. In fact, I think most of the time with negative values it should stay at the bottom of the chart like it is. The axis would end up getting in the way and the labels would be hard to read.

Take another charting library for example https://www.highcharts.com/demo/highcharts/column-negative

Can you give a mockup of what you want? I'm not sure it's going to look good with the axis and its labels in the middle of the chart

Hi,
I would want something like below. the x-axis line should be at zero. Is there a way to achieve this using workaround reference lines and custom ticks .
image

@ckifer
Copy link
Member

ckifer commented Mar 20, 2024

You can definitely keep the XAxis, hide it with hide, then place a reference line at 0. There's not an easy way to make ticks for that line though.

I'll try to see if there are any options to make a custom axis in a bit, currently replying from my phone so can't test anything

@albert-kp
Copy link
Author

You can definitely keep the XAxis, hide it with hide, then place a reference line at 0. There's not an easy way to make ticks for that line though.

I'll try to see if there are any options to make a custom axis in a bit, currently replying from my phone so can't test anything

I have tried to acheive with reference line and custom tick. But need to identify the exact position of zero tick so that i can postion the custom ticks to y position.

const CustomXAxisTicks = ({ x, payload }: any) => { console.log(x); return ( <g transform={translate(${x},${0})}> <text x={0} y={0} dy={16} textAnchor={'middle'} fill="#666"> {payload.value} </text> </g> ); };

<ReferenceLine y={0} stroke={'black'} />
See this example
image

https://stackblitz.com/edit/vitejs-vite-e7d1ag?file=src%2FApp.tsx

@ckifer
Copy link
Member

ckifer commented Mar 20, 2024

Ok so this solution is very very hacky and very much a workaround but in lieu of anything else

Edit simple-line-chart (forked)

image

@ckifer ckifer added enhancement Enhancement to a current API feature request Issues that are feature requests labels Mar 20, 2024
@ckifer ckifer changed the title Xaxis Line should start at 0 position in yaxis for charts with positive and negative values Allow X/YAxis to start be anchored to a certain value like ReferenceLine Mar 20, 2024
@ckifer
Copy link
Member

ckifer commented Mar 20, 2024

edited the title to make the issue easier to find later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement to a current API feature request Issues that are feature requests
Projects
None yet
Development

No branches or pull requests

2 participants