Vega: Access to data

Hi everyone,

I'm trying to create a Vega visualization. Here is a short extract of the code:

...
   "data": [
        {
          "name": "ttchanges",
          "url": {
            "%context%": true,
            "%timefield%": "changedate",
            "index": "ttableschanges_*",
            "body": {
              "aggs": {
                "tb": {
                  "date_histogram": {
                    "field": "changedate",
                    "interval": "1d"
                  },
                  "aggs": {
                    "bucket2": {
                      "terms": {
                        "field": "techtablename.keyword",
                        "size": 40,
                        "order": {
                          "_count": "desc"
                        },
                        "valueType": "string"
                      }
                    }
                  }
                }
              }
            }
          },
          "format": {
            "property": "aggregations.tb.buckets"
          },

          "transform": [
            {
              "type": "formula",
              "as": "ch_date",
              "expr": "datetime(datum.key)"
            }
          ]
        }
      ],
      "scales": [
        {
          "name": "xscale",
          "type": "time",
          "range": "width",
          "round": true,
          "domain": {
            "data": "ttchanges",
            "field": "ch_date"
          }
        },
        {
          "name": "yscale",
          "type": "band",
          "range": "height",
          "round": true,
          "padding": 0,
          "domain": {
            "data": "ttchanges",
            "field": "*datum*"
          }
        }
      ] ...

Now my question. In the yscale I would like to access a field (where it says datum right now) from the second aggregation which is called bucket2. How do I do this? I was able to access the key with datum.key to transform it to a proper date, but don't know how to go from there... tried datum.bucket2['xyz'] and couple of other things, but nothing works....
Would appreciate any help/hint!

Thank you!

Here's some more information
This is what the data looks like in the debug view. I'd like to access the bucket2 array in each data point.
Not sure whether I have to format my data differently. Currently I'm using

"format": {
            "property": "aggregations.tb.buckets"
          },

As "bucket2" is an array within the current "datum" data point, I guess my question is, how do I access an array in a datapoint?

Hi @MimmiXYZ,

you can access bucket2 via its own name, you do not have to use datum.bucket2 in this case, as the whole datum includes this field. So, you can use:

{
          "name": "yscale",
          "type": "band",
          "range": "height",
          "round": true,
          "padding": 0,
          "domain": {
            "data": "ttchanges",
            "field": "bucket2.some_nested_field.some_other_field"
          }
        }
´´´

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.