[![chart showing numbers without correct formatting][1]][1]
I need to format the label on these bars, so that they are rounded to nearest whole number. I have the following code:
def chart_tender_response_times(dataframe=None):
chart = (
alt.Chart(dataframe, title="Median time to respond to a tender")
.mark_bar()
.encode(
alt.X("year(date):O"
),
alt.Y("mean(median_duration):Q",
## This is our units section, only describe the units of measurement here.
axis=alt.Axis(title="Unit: days.")
),
alt.Tooltip(["mean(median_duration):Q"], format=",.2r", title="Days to respond to a tender")
)
)
text = (
chart.mark_text(align="center", baseline="bottom")
.encode(text='mean(median_duration):Q')
)
return chart+text
I've tried variations of the following...
text = (
chart.mark_text(align="center", baseline="bottom")
.encode(text='mean(median_duration):Q', format='.,2r')
)
but this returns the following schema validation error:
SchemaValidationError: Invalid specification
altair.vegalite.v3.api.Chart, validating 'required'
'data' is a required property
My hunch is that I have to somehow call and format the value, before adding it to the chart, but I can't see how to do this from either the documentation or the examples.