-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[charts] How to display given time as local time in a LineChart #11374
Comments
Hey @jvskriubakken ... could you provide us with a minimal example of it? |
OK. I have tried to create an example based on your starting point: In my browser (Chrome v120), the dates are displayed in UTC time, and the date times are formatted in english locale (12 hour clock with AM/PM). I expect or want the date times formatted in my norwegian locale (24 hour clock, and dates as: day-of-month/month/year) |
In that case your best bet is to use an external date library like dayjs, since date formatting is a pretty bad experience with the built in Check out this little demo i built on top of your example. Is this about the result you are looking for? For the tooltip header value: @alexfauquette can we change the format of those independently? Like with a custom component (as a last resort)? |
Being able to format differently for tootlip and axis is not yet feasible +1 for using a date library. If you don't use it in the rest of your app, maybe digging into the native toLocaleTimeString could worth it |
+1 on what @alexfauquette wrote. @jvskriubakken the only way you can take to get what you are aiming for is to use the slots, more specifically I have updated my previous demo with a very minimalistic approach here. Let me know if this is sufficient for you. Thanks! 🙇🏼 |
Hi, thanks for all the input guys. I managed to change x-axis tick labels by giving the the following valueFormatter in the x-axis config:
I notice that the ChartsTooltip (I am using ResponsiveChartContainer now) displays the given utc date time in local time by it self. But when I override the valueFormatter on x-axis, then ChartsTooltip seems to use that valueFormatter for x-value too. |
I understand now, that to be able to display a full date time in the ChartsTooltip I need to override the slots.axisContent :-) Thanks! |
Is there anything else regarding this that we can help you with @jvskriubakken? |
No it's fine then! Thanks! |
The problem in depth 🔍
Hi
I am using charts - line chart, and have set the x-axis to be the time axis (scaleType: "utc"). The time is displayed in UTC, but I want to display the in local time, what is the best way to achieve that? Same question goes for local formatting of the date time.
Your environment 🌎
Browser: Chrome v120
`npx @mui/envinfo`
Search keywords: charts utc time local
Order ID: 78678
The text was updated successfully, but these errors were encountered: