Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue building multi view chart in Vega using multiple aggs/nested #67

Open
Vannazux opened this issue May 16, 2018 · 0 comments
Open

Comments

@Vannazux
Copy link

Vannazux commented May 16, 2018

I am having a hard time figuring out how to build a multiview chart in Vega using aggregated/nested.

I believe it is related to the way I am trying to transform my data to use in Vega multi view chart. Can anyone give me a hand to understand this?

I know now flatten transformation is working as debug shows

image

But what I get is this

capture10

This is what I would like to achieve

capture

This is my schema to build the chart

{
  "$schema": "https://vega.github.io/schema/vega/v3.json",
  "width": 400,
  "height": 200,
  "padding": 5,
  "data": [
    {
      "name": "source",
      "values": {
        "aggregations": {
          "order_labels": {
            "buckets": [
              {
                "key": "USD/CAD",
                "doc_count": 1,
                "orders": {
                  "doc_count": 40,
                  "orders_id": {
                    "buckets": [
                      {
                        "key": 5241,
                        "doc_count": 1,
                        "orders_price": {"value": 0.01991}
                      },
                      {
                        "key": 5242,
                        "doc_count": 1,
                        "orders_price": {"value": 0.02021}
                      }
                    ]
                  }
                }
              },
              {
                "key": "CAD/COD",
                "doc_count": 1,
                "orders": {
                  "doc_count": 40,
                  "orders_id": {
                    "buckets": [
                      {
                        "key": 5041,
                        "doc_count": 1,
                        "orders_price": {"value": 0.00002953}
                      },
                      {
                        "key": 5042,
                        "doc_count": 1,
                        "orders_price": {"value": 0.00002971}
                      }
                    ]
                  }
                }
              }
            ]
          }
        }
      },
    "format": {"property": "aggregations.order_labels.buckets"},
    "transform": [
      {
        "type": "flatten",
        "fields": ["orders.orders_id.buckets"],
        "as": ["orders"]
      }
    ]
  }
  ],
  "mark": "bar",
  "encoding": {
    "row": {
      "field": "orders.key",
      "type": "ordinal"
    },
    "x": {
      "aggregate": "sum",
      "field": "orders.orders_price.value",
      "type": "quantitative",
      "scale": { "zero": false }
    },
    "y": {
      "field": "key",
      "type": "ordinal",
      "scale": { "rangeStep": 12 }
    }
  }
}

I did many things but can`t understand what is wrong with it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant