如果我有聚合的时间序列数据。是否可以执行额外的聚合并将其显示在工具提示中?
这是我的问题的一个更明确的例子。对于下面的代码示例,我们显示了三种不同类型水果按月汇总的权重总和。是否也可以将每个月的总重量(和/或每个月按水果划分的标准化重量百分比)显示为标签或工具提示?
我玩过transform_aggregate
但似乎无法让它工作(它最终破坏了group by
水果)。:(
dates = np.array([
np.datetime64('200%s-%.02d-%.02d' % (i,j,k))
for i in range(5)
for j in range(1,13)
for k in range(1, 29)])
data = pd.DataFrame({
'timestamp': dates,
'weight': np.random.randint(0, 20, 1680),
'fruit': np.random.randint(0,3, 1680)
})
date_month = alt.X('yearmonth(timestamp):O', title='Month')
total = alt.Y('weight:Q', aggregate='sum', title='Metric')
(alt.Chart(data).mark_bar().encode(
x=date_month,
y=total,
color='fruit',
tooltip=[date_month, total, 'fruit']
))