我正在使用mongo db BI连接器,并尝试使用cube.js呈现日期序列图。有没有办法在日期范围内应用时间维度并仅考虑工作日? 下面是我的示例多维数据集架构和集合
cube(`Entries`, {
sql: `SELECT * FROM db.entries`,
measures: {
count: {
type: `count`
}
},
dimensions: {
result: {
sql: `result`,
type: `string`
},
date: {
sql: `date`,
type: `time`
},
},
});
查询:
{
"measures": [
"Entries.count"
],
"timeDimensions": [
{
"dimension": "Entries.date",
"granularity": "day"
}
]
}
答案 0 :(得分:0)
您可以通过引入weekdays
段来实现:
cube(`Entries`, {
sql: `SELECT * FROM db.entries`,
measures: {
count: {
type: `count`
}
},
dimensions: {
result: {
sql: `result`,
type: `string`
},
date: {
sql: `date`,
type: `time`
},
},
segments: {
weekdays: {
sql: `DAYOFWEEK(${date}) <> 1 AND DAYOFWEEK(${date}) <> 7`
}
}
});
并在查询中使用它,例如:
{
"measures": [
"Entries.count"
],
"timeDimensions": [
{
"dimension": "Entries.date",
"granularity": "day"
}
],
"segments": ["Entries.weekdays"]
}
要隐藏零个周末值,请在准备数据时通过fillMissingDates: false
:
resultSet.chartPivot({ fillMissingDates: false })
有关细分的更多信息,请点击此处:https://cube.dev/docs/segments