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

X-axis times ticks are not display major hour like 11:00 12:00 #4537

Closed
sohagmahin opened this issue May 17, 2024 · 9 comments
Closed

X-axis times ticks are not display major hour like 11:00 12:00 #4537

sohagmahin opened this issue May 17, 2024 · 9 comments
Labels
pending response Pending response from the issue requester

Comments

@sohagmahin
Copy link

I want to display x-axis ticks hourly value like that 11:00 or 12:00
if there any new day come then display 14 May 2024 11:00

Is that possible with recharts?

Here is my code snippet.
https://codesandbox.io/p/sandbox/recharts-issue-template-forked-dpq4rd

@ckifer
Copy link
Member

ckifer commented May 17, 2024

Sure, but as it stands your data in iso format will not get parsed correctly. In order for recharts to interpret time correctly it needs to be in milliseconds. This way it can plot time along a numerical axis and you can use the formatter function to display as you wish.

hopefully we can support parsing iso timestamps in the future

@sohagmahin
Copy link
Author

sohagmahin commented May 17, 2024

@ckifer Updated times to milliseconds now. But I can not figure out how to display major hour ticks like that 11:00, 12:00, though there is no data with that time.

https://codesandbox.io/p/sandbox/recharts-issue-template-forked-dpq4rd

@ckifer
Copy link
Member

ckifer commented May 17, 2024

Yeah, this needs to be easier.

Essentially what you would have to do is precalculate what those ticks would be in numeric value and then add them to the XAxis ticks array. The axis also needs to be "number" type in order to be able to interpolate.

  1. Get time where you want to start / end
  2. Get hours between
  3. Convert to numbers
  4. Add to ticks array

Edit recharts-issue-template (forked)

Not sure about adding a differentiation when the day changes, but there should be a way to figure that out

@ckifer
Copy link
Member

ckifer commented May 17, 2024

Edited the sandbox with detecting when the day changes, ended up being very simple. Let me know if this solves your usecase!

@ckifer ckifer added the pending response Pending response from the issue requester label May 17, 2024
@ckifer
Copy link
Member

ckifer commented May 17, 2024

image

@ckifer
Copy link
Member

ckifer commented May 20, 2024

Going to close this as answered, feel free to comment back if there are issues

@ckifer ckifer closed this as completed May 20, 2024
@sohagmahin
Copy link
Author

Thanks @ckifer. It works.

@sohagmahin
Copy link
Author

@ckifer New Day ticks not rendering correctly. Like Here the new day is 16 May 00:06 but ticks rendered 16 May 03:00
Screenshot 2024-05-21 at 7 49 47 PM

@ckifer
Copy link
Member

ckifer commented May 21, 2024

It's only going to run the formatter function on the ticks that are actually shown. So unless you angle the ticks to get more to show, always the first one that is showing in that day will have the extra label

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending response Pending response from the issue requester
Projects
None yet
Development

No branches or pull requests

2 participants