# Vega plot y-axis "undefined"

**URL:** https://discuss.elastic.co/t/vega-plot-y-axis-undefined/243503
**Category:** Kibana
**Tags:** vega
**Created:** [August 3, 2020, 6:05am UTC](https://discuss.elastic.co/t/vega-plot-y-axis-undefined/243503 "2020-08-03T06:05:34Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![dataplatform12345](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dataplatform12345](https://discuss.elastic.co/u/dataplatform12345)
#### Post date: [August 3, 2020, 6:05am UTC](https://discuss.elastic.co/t/vega-plot-y-axis-undefined/243503/1 "2020-08-03T06:05:34Z")

</div>

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.

```auto
    {
  $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"}
        }
      }
    }
  ]
  
}

```

---

<div class="post-metadata">

### Author: ![Midas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/midas/32/50275_2.png) [@Midas](https://discuss.elastic.co/u/Midas)
#### Post date: [August 12, 2020, 12:47am UTC](https://discuss.elastic.co/t/vega-plot-y-axis-undefined/243503/2 "2020-08-12T00:47:46Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [September 9, 2020, 12:47am UTC](https://discuss.elastic.co/t/vega-plot-y-axis-undefined/243503/3 "2020-09-09T00:47:48Z")

</div>

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