简体   繁体   English

如何将限制过滤器应用于cubeJs 的timeDimension 属性?

[英]How can I apply limit filter to the timeDimension property of cubeJs?

Below is the scenario where I'm trying to apply a limit of 2 using cubejs.下面是我尝试使用cubejs 应用限制为2 的场景。 Here is the json query for this :这是对此的 json 查询:

{
    "measures": [
        "actors.actorscount"
    ],
    "timeDimensions": [
        {
            "dimension": "actors.createdAt",
            "granularity": "month",
            "dateRange": "Last quarter"
        }
    ],
    "dimensions": [
        "actors.genre"
    ],
    "filters": []
}

在此处输入图片说明

And after applying limit=2 to below query, I'm getting below bar-graph response:在将 limit=2 应用于以下查询后,我得到了低于条形图的响应:

{
        "measures": [
            "actors.actorscount"
        ],
            "timeDimensions": [
                {
                    "dimension": "actors.createdAt",
                    "granularity": "month",
                    "dateRange": "Last quarter"
                }
            ],
                "dimensions": [
                    "actors.genre"
                ],
                    "filters": [],
                    "limit":2
    }

and the current bar-graph I'm getting as :和我得到的当前条形图: 在此处输入图片说明

Expecting bar-graph response after applying limit :应用限制后预期条形图响应:

在此处输入图片说明

so, what should be done to get the correct bar-graph response?那么,应该怎么做才能获得正确的条形图响应?

Such result can be achieved in 2 steps:这样的结果可以通过 2 个步骤来实现:

First to get top 2 dimensions without time granularity:首先获得没有时间粒度的前 2 个维度:

{
    "measures": [
        "actors.actorscount"
    ],
    "timeDimensions": [
        {
            "dimension": "actors.createdAt",
            "dateRange": "Last quarter"
        }
    ],
    "dimensions": [
        "actors.genre"
    ],
    "order": { "actors.actorscount": "desc" },
    "limit": 2
}

Then use two top dimensions from first query result to get desired chart:然后使用第一个查询结果中的两个顶部维度来获得所需的图表:

{
    "measures": [
        "actors.actorscount"
    ],
    "timeDimensions": [
        {
            "dimension": "actors.createdAt",
            "granularity": "month"
            "dateRange": "Last quarter"
        }
    ],
    "dimensions": [
        "actors.genre"
    ],
    "filters": [{
      "dimension": "actors.genre",
      "operator": "equals",
      "values": ["action", "comedy"]
    }]
}

The dimensions array contains only one value inside but it is having a comma after that value which is the wrong syntax.维度数组内部仅包含一个值,但该值后面有一个逗号,这是错误的语法。 You have to fix this.你必须解决这个问题。 (Remove the comma and your code will work). (删除逗号,您的代码将起作用)。

在此处输入图片说明

Please remove the "limit" key-value pair from "timeDimensions" array and add it as independent key-value pair not under some property.请从“timeDimensions”数组中删除“limit”键值对并将其添加为不在某些属性下的独立键值对。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM