GitHub user dosubot[bot] added a comment to the discussion: Compilation of
query data for a POST request
<!-- Answer -->
To build a multi-level X-axis with `ds` and `TAXI_OUT`, you need to include
both columns in the `columns` array of your query. Here's an example POST
request to `/api/v1/chart/data`:
```json
{
"datasource": {"id": YOUR_DATASOURCE_ID, "type": "table"},
"queries": [{
"columns": ["ds", "TAXI_OUT"],
"metrics": [{"label": "your_metric"}],
"row_limit": 1000,
"time_range": "Last year",
"post_processing": []
}],
"result_type": "results"
}
```
With `result_type: "results"`, the response will return a simplified structure
with just your data:
```json
{
"data": [...],
"colnames": ["ds", "TAXI_OUT", ...],
"coltypes": [...],
"rowcount": 100
}
```
For `post_processing`, if you don't need additional transformations, you can
leave it as an empty array `[]`. If you need to transform the data further,
available operations include `aggregate`, `sort`, `pivot`, `rolling`, etc. For
example, to sort by `ds`:
```json
"post_processing": [{
"operation": "sort",
"options": {
"by": ["ds"],
"ascending": [true]
}
}]
```
The order of columns in the `columns` array determines the hierarchy - so
`["ds", "TAXI_OUT"]` creates a [two-level
grouping](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/models/helpers.py#L1614-L1653)
where data is first grouped by `ds`, then by `TAXI_OUT`.
<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*
---
<sup>How did I do?
[Good](https://app.dosu.dev/response-feedback/76c32625-4fb7-43bc-8a5d-0c4c627a775e?feedback_type=great_response)
|
[Irrelevant](https://app.dosu.dev/response-feedback/76c32625-4fb7-43bc-8a5d-0c4c627a775e?feedback_type=irrelevant_answer)
|
[Incorrect](https://app.dosu.dev/response-feedback/76c32625-4fb7-43bc-8a5d-0c4c627a775e?feedback_type=incorrect_sources)
|
[Verbose](https://app.dosu.dev/response-feedback/76c32625-4fb7-43bc-8a5d-0c4c627a775e?feedback_type=too_verbose)
|
[Hallucination](https://app.dosu.dev/response-feedback/76c32625-4fb7-43bc-8a5d-0c4c627a775e?feedback_type=hallucination)
| [Report
🐛](https://app.dosu.dev/response-feedback/76c32625-4fb7-43bc-8a5d-0c4c627a775e?feedback_type=bug_report)
|
[Other](https://app.dosu.dev/response-feedback/76c32625-4fb7-43bc-8a5d-0c4c627a775e?feedback_type=other)</sup>
[](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=github) [](https://cursor.com/link/prompt?text=To%20build%20a%20multi-level%20X-axis%20with%20%60ds%60%20and%20%60TAXI_OUT%60%2C%20you%20need%20to%20include%20both%20columns%20in%20the%20%60columns%60%20array%20of%20your%20query.%20Here%27s%20an%20example%20POST%20request%20to%20%60/api/v1/chart/data%60%3A%0A%0A%60%60%60json%0A%7B%0A%20%20%22datasource%22%3A%20%7B%22id%22%3A%20YOUR_DATASOURCE_ID%2C%20%22type%22%3A%20%22table%22%7D%2C%0A%20%20%22queries%22%3A%20%5B%7B%0A%20%20%20%20%22columns%22%3A%20%5B%22ds%22%2C%20%22TAXI_OUT%22%5D%2C%0A%20%20%20%20%22metrics%22%3A%20%5B%7B%22label%22%3A%20%22your_metric%22%7D%5D%2C%0A%20%20%20%20%22row_limit%22%3A%201000%2C%0A%20%20%20%20%22time_range%22%3A%20%22Last%20year%22%2C%0A%20%20%20%20%22post_processing%22%3A%20%5B%5D%0A%20%20%7D%5D%2C%0A%20%20%22resul
t_type%22%3A%20%22results%22%0A%7D%0A%60%60%60%0A%0AWith%20%60result_type%3A%20%22results%22%60%2C%20the%20response%20will%20return%20a%20simplified%20structure%20with%20just%20your%20data%3A%0A%0A%60%60%60json%0A%7B%0A%20%20%22data%22%3A%20%5B...%5D%2C%0A%20%20%22colnames%22%3A%20%5B%22ds%22%2C%20%22TAXI_OUT%22%2C%20...%5D%2C%0A%20%20%22coltypes%22%3A%20%5B...%5D%2C%0A%20%20%22rowcount%22%3A%20100%0A%7D%0A%60%60%60%0A%0AFor%20%60post_processing%60%2C%20if%20you%20don%27t%20need%20additional%20transformations%2C%20you%20can%20leave%20it%20as%20an%20empty%20array%20%60%5B%5D%60.%20If%20you%20need%20to%20transform%20the%20data%20further%2C%20available%20operations%20include%20%60aggregate%60%2C%20%60sort%60%2C%20%60pivot%60%2C%20%60rolling%60%2C%20etc.%20For%20example%2C%20to%20sort%20by%20%60ds%60%3A%0A%0A%60%60%60json%0A%22post_processing%22%3A%20%5B%7B%0A%20%20%22operation%22%3A%20%22sort%22%2C%0A%20%20%22options%22%3A%20%7B%0A%20%20%20%20%22by%22%3A%20%5B%22ds%22%5D%2C%0A%20%20%20
%20%22ascending%22%3A%20%5Btrue%5D%0A%20%20%7D%0A%7D%5D%0A%60%60%60%0A%0AThe%20order%20of%20columns%20in%20the%20%60columns%60%20array%20determines%20the%20hierarchy%20-%20so%20%60%5B%22ds%22%2C%20%22TAXI_OUT%22%5D%60%20creates%20a%20%5Btwo-level%20grouping%5D%28https%3A//github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/models/helpers.py%23L1614-L1653%29%20where%20data%20is%20first%20grouped%20by%20%60ds%60%2C%20then%20by%20%60TAXI_OUT%60.) [](https://go.dosu.dev/discord-bot) [](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/discussions/38011)
GitHub link:
https://github.com/apache/superset/discussions/38011#discussioncomment-15823324
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]