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
Tooltip and axis labels are not displaying correct date for st.altair_chart
#4342
Comments
I'm facing a similar issue. Try changing your tooltip line to Say your machine is in UTC-5, you'll probably find that where It seems like Streamlit is converting the datetimes to the timezone on the local machine. If no tz info is specified for the datetime given, it assumes UTC. From what I've tried, this only seems to be happening to Altair charts in Streamlit. It does not happen to Altair on its own, and it does not happen to |
Thanks for reporting this issue! As suggested by @arcanaxion, the problem is indeed related to how altair processes date timezones. One fix from our side might be to always set the scale to |
This seems very related to vega/altair#2540 The solution would be to put the dates into the ISO-8601 format. |
I'm bumping this up to a P2 since it also impacts the axis labels (as seen in the screenshot above) and we heard about it from a few places recently. I don't think the provided workaround would fix the axis labels, just the tooltip. I don't have edit access on the issue, but would be nice if someone could update the title and summary to reflect that it's not just the tooltip impacted. |
st.altair_chart
Confirming that I experience this issue in the U.S. when using Streamlit, and not in Europe when using Streamlit. It works everywhere in Jupyter notebook (without the I suggest for the title to be "Tooltip and axis labels are not displaying correct for |
Still experiencing this as of Feb 2024, not a nice bug. I'm changing all tooltips to use a stringified version of the date meanwhile. :/ |
Running into the issue as well. It seems like streamlit needs to set the scale property on the Tooltip as well as on the axis markers as per vega/altair#2077 (comment)
Though apparently Altair does not support this Vega feature, so this probably needs a fix in Altair first... |
## Describe your changes When Streamlit apps work with dates/datetime, Vega can show the incorrect date on the graphs. This is because datetimes are serialized as milliseconds since epoch and are therefore assumed in UTC format. Vega's engine takes in this timestamp and produces a Date that is set to the local timezone, which can create some incorrect values. There's also no way to determined from the serialized shape what timezone it is in, so we need to offset the time for vega. NOTE: We do this a lot in formatting for tables, but this is specific to Vega's engine, so we isolate the change there. ## GitHub Issue Link (if applicable) Closes #4342 ## Testing Plan - JS Unit Tests are included and updated to test DATE, DATETIME, and DATETIMETZ formats. - Checking rendering of E2E Tests for the tooltip (like in the issue) is really difficult. Manual testing of this is possible with PR Preview. --- **Contribution License Agreement** By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.
Summary
When plotting an Altair plot with date in tooltip, display is incorrect
Steps to reproduce
Code snippet:
Expected behavior:
I expected to see June 4th 2015 and I saw June 3rd 2015.
Actual behavior:
Please see above
Is this a regression?
don't know.
Debug info
Additional information
I looked into already published issues and I could not find anything related to this. Thank you.
The text was updated successfully, but these errors were encountered: