Vega plot y-axis "undefined"

Hi all,

I'm trying to plot a simple horizontal bar chart using vega in Kibana after transforming the original index using a groupby aggregate. It appears the plotting doesn't work and the y-axis scale ends up as "undefined". x-axis seems to populate the data from the aggregate sum field.
The transformation itself works and I could see data in data_set_02 using VIEW_DEBUG.view('data_set_02'). Any pointers to debug this will be really helpful or please let me know if there is anything missing in the vega code. Thanks.

    {
  $schema: https://vega.github/io/schema/vega/v4.json
  description: test
  padding: 5
  autosize: fit
  

  title: {
    text: "Top x"
  } 
  
  data: [
    {
     name: "data_set_01",
     url: {
       index: data_set_01
     },
     format: {
       property: hits.hits
     }
    },
    
    {
     name: "data_set_02"
     source: "data_set_01",
     transform: [
        {
        type: "aggregate",
        groupby: ["_source.id_col"],
        ops: ["sum"],
        fields: ["_source.value_col"],
        as: ["value_sum"]
      }
     ]
    }
    
  ]
  
  
  scales: [
  {
    name: "xscale",
    type: "linear",
    domain: {data: "data_set_02", field: "value_sum"},
    range: "width",
    nice: true
  },
  {
    name: "yscale",
    type: "band",
    domain: {data: "data_set_02", field: "id_col"},
    range: "height",
    padding: 0.1
  }
  ],
  
  axes: [
    {
      scale: "xscale",
      orient: "bottom"
    },
    {
      scale: "yscale",
      orient: "left"
    }
  ],
  
  marks: [
    {
      type: "rect",
      from: {data: "data_set_02"},
      encode": {
        "enter": {
          "x": {"scale": "xscale", "field": "id_col"},
          "width": {"scale": "xscale", "band": 1},
          "y": {"scale": "yscale", "field": "value_sum"},
          "y2": {"scale": "yscale", "value": 0}
        },
        "update": {
          "fill": {"value": "steelblue"}
        },
        "hover": {
          "fill": {"value": "red"}
        }
      }
    }
  ]
  
}

dataplatform,

This should be easy to fix. Just add a project transform before your aggregate. For some odd reason, scales and marks don't like seeing a '.' in the field names. Something like this should do:

{
 name: "data_set_02"
 source: "data_set_01",
 transform: [
   {"type": "project", "fields": ["_source.id_col", "_source.value_col"], "as": ["id_col", "value"]},
   {"type": "aggregate", "groupby": ["id_col"], "ops": ["sum"], "fields": ["value"], "as": ["value_sum"]}
 ]
}

That should do the trick. Let me know if that works for you!

-Midas

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