[英]Cube.js time series excluding weekends
I am using mongo db BI connector and trying to render date series charts using cube.js.我正在使用 mongo db BI 连接器并尝试使用 cube.js 呈现日期系列图表。 Is there a way to apply time dimension with a date range and considering only business days?
有没有办法应用日期范围的时间维度并只考虑工作日? Below are my sample cube schema and collection
以下是我的示例多维数据集架构和集合
cube(`Entries`, {
sql: `SELECT * FROM db.entries`,
measures: {
count: {
type: `count`
}
},
dimensions: {
result: {
sql: `result`,
type: `string`
},
date: {
sql: `date`,
type: `time`
},
},
});
Query:询问:
{
"measures": [
"Entries.count"
],
"timeDimensions": [
{
"dimension": "Entries.date",
"granularity": "day"
}
]
}
You can do this by introducing weekdays
segment:您可以通过引入
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`
}
}
});
And use it in query like:并在查询中使用它,例如:
{
"measures": [
"Entries.count"
],
"timeDimensions": [
{
"dimension": "Entries.date",
"granularity": "day"
}
],
"segments": ["Entries.weekdays"]
}
To hide zero weekend values pass fillMissingDates: false
when preparing the data:要隐藏零周末值,请在准备数据时通过
fillMissingDates: false
:
resultSet.chartPivot({ fillMissingDates: false })
More info about segments here: https://cube.dev/docs/segments有关片段的更多信息: https://cube.dev/docs/segments
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.