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

Repeated values in date axis #2876

Closed
lucasbalponti opened this issue Feb 7, 2023 · 4 comments
Closed

Repeated values in date axis #2876

lucasbalponti opened this issue Feb 7, 2023 · 4 comments
Labels

Comments

@lucasbalponti
Copy link

Hello guys!

I'm trying to make a bar graph which has its X axis's type as time. I formatted it using 'utcyearmonth', but the X axis's label repeats values.

Is it a bug? Is there a way to solve it?

This is what happens to the graph

The code I've written is:

serie_temporal = alt.Chart(base_filtrada).mark_bar(size=60).encode(
    x=alt.X(
        'utcyearmonth(Data):T', 
        axis=alt.Axis(format="%Y %B"),
        scale = alt.Scale(nice={'interval': 'month', 'step': 1})
    ),
    y='sum(Valor):Q',
    color='Tipo de despesa'
).properties(
    height=400
)

I already tried changing the axis type from time to nominal, ordinal and quantitative and removing the scale configuration.

Thank you in advance!

@ChristopherDavisUCI
Copy link
Contributor

Hi! It's a little hard to debug for me without seeing the data. I looked at a few similar examples from the Altair docs and they seemed to use a little different strategy:

I would also start without the axis and scale arguments, just so at first there are fewer parts making adjustments.

Does that help? If not, can you post an example of the behavior using one of the datasets from vega_datasets, like in the gallery examples?

@lucasbalponti
Copy link
Author

lucasbalponti commented Feb 7, 2023

Hi Cristopher,

Your first suggestion solved my problem ( x = alt.X("date:O", timeUnit="yearmonth") ):

How it looks now

Thank you for the precise and quick answer!

@lucasbalponti
Copy link
Author

Update: i realized that after i made the change, the dates were off by one day.

But then i just transformed the dates to a string, formatted like ISO 8601, added my timezone info, and everything worked perfectly!

image

@joelostblom
Copy link
Contributor

Closing as resolved. Some more info on the off-by-one dates in this issue #2540

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

No branches or pull requests

3 participants