将秒转换为轴标签的天、小时等
我想画一个图表,Y轴需要显示“天、小时、分钟”的时间段,X轴则只显示日期。如果时间段用秒来表示,我可以很容易做到,但为了让图表更易读,我想把Y轴的标签改成类似于DTHH:MM
的格式,比如1 Day(s) 10:23
。有没有人知道怎么实现这个?
这是我现在的代码片段:
chart = (
alt.Chart(aggregated_df, title=metric_name_to_display)
.mark_line(point=True)
.encode(
alt.X(f"yearmonthdatehours({QUERY_TIME_COLUMN_NAME}):O").title("Date"),
alt.Y(f"{metric_name}:Q").title(metric_name_to_display),
alt.Color("Index:N"), # type: ignore
alt.Tooltip(
[metric_name, f"yearmonthdatehours({QUERY_TIME_COLUMN_NAME}):O"]
),
)
)
其中aggregated_df
的格式是
query_time recovered_seconds_all_ingest
0 2024-01-01 00:00:00+00:00 827183
1 2024-01-01 12:00:00+00:00 1832
2 2024-01-02 00:00:00+00:00 829301
3 2024-01-02 12:00:00+00:00 29191
0 个回答
暂无回答