发布于 2021-12-26 14:30:15
我尝试使用timeUnitSpecifier转换日期字段,并将它用作x轴的标称字段,这似乎是正确地从params转换和使用我的时间单位。我没有找到任何支持expr配置的timeUnit。但是我的例子不是时间上的,所以不会有任何连续的轴。
下面是配置或引用编辑器示例:
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "...",
"width": 400,
"height": 300,
"padding": 5,
"data": {
"values": [
{"opened": "2021-01-12 11:11:12"},
{"opened": "2021-01-13 11:11:02"},
{"opened": "2021-01-14 01:11:54"},
{"opened": "2021-02-12 01:11:34"},
{"opened": "2021-02-18 02:11:02"},
{"opened": "2021-02-22 03:31:10"},
{"opened": "2021-03-07 04:35:32"},
{"opened": "2021-03-21 11:31:54"},
{"opened": "2021-03-22 11:36:22"},
{"opened": "2021-03-29 01:35:52"}
]
},
"params": [
{
"name": "aggWindow",
"value": "date",
"bind": {
"name": "Time period ",
"input": "select",
"options": [["month","date"], "date", "week", "month"]
}
}
],
"transform": [
{
"calculate": "timeFormat(time(datum.opened), timeUnitSpecifier(aggWindow))",
"as": "convertedDate"
}
],
"mark": "bar",
"encoding": {
"x": {"field": "convertedDate", "type": "nominal"},
"y": {"aggregate": "count", "type": "quantitative"}
}
}https://stackoverflow.com/questions/70483319
复制相似问题