我有一个有两个日期的桌子,我想要创建一个有‘延迟’和‘准时’切片(‘延迟’如果Date2>Date1,‘准时’如果Date2<=Date1)的2切片饼图。
你会向织女星初学者推荐什么策略?
我的想法:
{“计算”:"datum.Date1 - datum.Date2","as":"DateDifference"}
任何想法都是非常感谢的!
发布于 2021-02-01 13:45:31
您可以通过在计算转换中使用三元运算符来完成此操作:
{
"calculate": "toDate(datum.Date1) < toDate(datum.Date2) ? 'delayed' : 'on time'",
"as": "diff"
}下面是饼图(编辑视图)中的一个示例:
{
"data": {
"values": [
{"Date1": "2021-02-01T06:00:00", "Date2": "2021-02-01T05:50:00"},
{"Date1": "2021-02-01T07:00:00", "Date2": "2021-02-01T06:49:00"},
{"Date1": "2021-02-01T08:00:00", "Date2": "2021-02-01T08:15:00"},
{"Date1": "2021-02-01T09:00:00", "Date2": "2021-02-01T09:05:00"},
{"Date1": "2021-02-01T19:00:00", "Date2": "2021-02-01T09:59:00"}
]
},
"transform": [
{
"calculate": "toDate(datum.Date1) < toDate(datum.Date2) ? 'delayed' : 'on time'",
"as": "diff"
}
],
"mark": "arc",
"encoding": {
"theta": {"field": "diff", "aggregate": "count", "type": "quantitative"},
"color": {"field": "diff", "type": "nominal"}
},
"$schema": "https://vega.github.io/schema/vega-lite/v4.8.1.json"
}

https://stackoverflow.com/questions/65989344
复制相似问题