0
votes

From looking at https://vega.github.io/editor/#/examples/vega-lite/bar_grouped it shows example of creating grouped bar chart from a table of data.

In my case since I am getting data from elasticsearch it is not in tabular form.

I can't figure out a way to create two bar chart for each sum metric on a bucket.

"buckets" : [
        {
          "key_as_string" : "03/Dec/2019:00:00:00 +0900",
          "key" : 1575298800000,
          "doc_count" : 11187,
          "deploy_agg" : {
            "buckets" : {
              "deploy_count" : {
                "doc_count" : 43
              }
            }
          },
          "start_agg" : {
            "buckets" : {
              "start_count" : {
                "doc_count" : 171
              }
            }
          },
          "sum_start_agg" : {
            "value" : 171.0
          },
          "sum_deploy_agg" : {
            "value" : 43.0
          }
        },..

I want to create two bars, one representing value of sum_start_agg and another one representing sum_deploy_agg value.

This is what I had for one bar chart.

  "encoding": {
    "x": {
      "field": "key",
      "type": "temporal",
      "axis": {"title": "DATE"}
    },
    "y": {
      "field": "deploy_agg.buckets.deploy_count.doc_count",
      "type": "quantitative",
      "axis": {"title": "deploy_count"}
    }
    "color": {"value": "green"}
    "tooltip": [
        {
        "field": "deploy_agg.buckets.deploy_count.doc_count",
        "type": "quantitative",
        "title":"value"
        }
      ]
  }
1

1 Answers

0
votes

You can use the Fold Transform to fold your two columns so that they can be referenced in an encoding. It might look something like this:

{
  "data": {
    "values": [
      {
        "key_as_string": "03/Dec/2019:00:00:00 +0900",
        "key": 1575298800000,
        "doc_count": 11187,
        "deploy_agg": {"buckets": {"deploy_count": {"doc_count": 43}}},
        "start_agg": {"buckets": {"start_count": {"doc_count": 171}}},
        "sum_start_agg": {"value": 171},
        "sum_deploy_agg": {"value": 43}
      }
    ]
  },
  "transform": [
    {
      "fold": ["sum_start_agg.value", "sum_deploy_agg.value"],
      "as": ["entry", "value"]
    }
  ],
  "mark": "bar",
  "encoding": {
    "x": {"field": "entry", "type": "nominal", "axis": null},
    "y": {"field": "value", "type": "quantitative"},
    "column": {"field": "key", "type": "temporal"},
    "color": {"field": "entry", "type": "nominal"}
  }
}

enter image description here