# Vega Is Not Showing Anything Despite Code Passing Error-Free

**URL:** https://discuss.elastic.co/t/vega-is-not-showing-anything-despite-code-passing-error-free/239142
**Category:** Kibana
**Created:** [June 29, 2020, 3:24pm UTC](https://discuss.elastic.co/t/vega-is-not-showing-anything-despite-code-passing-error-free/239142 "2020-06-29T15:24:00Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Ethan777100](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ethan777100/32/70366_2.png) [@Ethan777100](https://discuss.elastic.co/u/Ethan777100)
#### Post date: [June 29, 2020, 3:24pm UTC](https://discuss.elastic.co/t/vega-is-not-showing-anything-despite-code-passing-error-free/239142/1 "2020-06-29T15:24:00Z")

</div>

im unable to get my Vega to show smth?

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/a/1/a161617ee3a140db8c1505825ddf36c8789d9ff6.png)  
this the o/p using Vega-Lite 2.0

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/3/7/375cb4d8b163eb71254597efb4475d29681fcae4.png)  
this is the o/p using Vega 4.0

```
{
"$schema": "https://vega.github.io/schema/vega/v4.json",
"data": {
  "url": {
    "%context%": true,
    "%timefield%": "DateTime",
    "index": "nsew*",
    "body": {
      "size": 10000,
      "_source": ["Current_Platform_Name", "Align_Distance_To_Go_mm","Train_Type"]
    }
  },
  "format": {"property": "hits.hits"}
},
"transform": [
 {"filter": {"field": "datum._source['Align_Distance_To_Go_mm']", "range": [-300, 300]}},
 {
   "joinaggregate": [{
     "op": "count",
     "field": "datum.Align_Distance_To_Go_mm",
     "as": "count_all_Dist"
    }],
    "groupby": ["Current_Platform_Name"]
  },
 
  {
    "joinaggregate": [{
      "op": "count",
      "field": "datum.Align_Distance_To_Go_mm",
      "as": "count_within_Dist"
    }],
    "groupby": ["Current_Platform_Name"]
    },
   {
    "calculate": " (datum.count_within_Dist/datum.count_all_Dist)*100 ",
    "as": "Percent_Compliance"
  }
],

"layer": [
{
"mark": "bar",
"height": {"step": 5},
"encoding": {
  "x": {
    "field": "Percent_Compliance",
    "type": "quantitative",
    "axis": {"title": "Percent_Compliance"}
  },
  "y": {
    "field": "_source.Current_Platform_Name",
    "type": "nominal",
    "axis": {"title": "Platform Name"}
  },
  "color": {
    "field": "_source.Current_Platform_Name",
    "type": "nominal",
    "legend": {"title": "Platform Legend"}
  },
  "shape": {"field": "_source.Current_Platform_Name", "type": "nominal"}
}
}
]

```

}

here is my code. i dont get why its not working out.

i do prefer using Vega 4.3.0 - so i do seek your advice from the Vega approach instead. Thanks

---

<div class="post-metadata">

### Author: ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)
#### Post date: [June 29, 2020, 3:46pm UTC](https://discuss.elastic.co/t/vega-is-not-showing-anything-despite-code-passing-error-free/239142/2 "2020-06-29T15:46:06Z")

</div>

I think your specs have multiple problems, and I will try to help you find those problems. The main problems are:

- Transforms that use `field` do not use `datum`. You should write `_source.Align_Distance_To_Go_mm` instead of `datum._source.Align_Distance_To_Go_mm` in transforms.
- Transforms are not the same in Vega and Vega-lite- you can't copy and paste from Vega-lite into Vega.

The best way to debug this is to use the browser dev tools and inspect the following two variables:

`VEGA_DEBUG.view.data('source_0')`  
`VEGA_DEBUG.view.data('data_0')`

In vega-lite, `datum` refers to `data_0`, while `source_0` is the ES data.

Putting this together, I think this is what you need to write:

```auto
"$schema": "https://vega.github.io/schema/vega-lite/v2.json",
...
"transform": [
 {"filter": {"field": "_source.Align_Distance_To_Go_mm", "range": [-300, 300]}},
 {
   "joinaggregate": [{
     "op": "count",
     "field": "_source.Align_Distance_To_Go_mm",
     "as": "count_all_Dist"
    }],
    "groupby": ["_source.Current_Platform_Name"]
  },
  {
    "joinaggregate": [{
      "op": "count",
      "field": "_source.Align_Distance_To_Go_mm",
      "as": "count_within_Dist"
    }],
    "groupby": ["_source.Current_Platform_Name"]
    },
   {
    "calculate": " (datum.count_within_Dist/datum.count_all_Dist)*100 ",
    "as": "Percent_Compliance"
  }
],

```

---

<div class="post-metadata">

### Author: ![Ethan777100](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ethan777100/32/70366_2.png) [@Ethan777100](https://discuss.elastic.co/u/Ethan777100)
#### Post date: [June 30, 2020, 2:21am UTC](https://discuss.elastic.co/t/vega-is-not-showing-anything-despite-code-passing-error-free/239142/3 "2020-06-30T02:21:50Z")

</div>

hi Wylie, thanks for ur explanation but hold on.

Am i only restricted to using Vega-Lite only for Kibana?

---

<div class="post-metadata">

### Author: ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)
#### Post date: [June 30, 2020, 3:03pm UTC](https://discuss.elastic.co/t/vega-is-not-showing-anything-despite-code-passing-error-free/239142/8 "2020-06-30T15:03:38Z")

</div>

I believe your issue is an invalid filter. Try this:

```auto
{ "filter": "datum._source.Align_Distance_To_Go_mm >= -300 && datum._source.Align_Distance_To_Go_mm <= 300" },

```

This visualization should be possible.

---

<div class="post-metadata">

### Author: ![Ethan777100](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ethan777100/32/70366_2.png) [@Ethan777100](https://discuss.elastic.co/u/Ethan777100)
#### Post date: [June 30, 2020, 3:04pm UTC](https://discuss.elastic.co/t/vega-is-not-showing-anything-despite-code-passing-error-free/239142/9 "2020-06-30T15:04:48Z")

</div>

![image](https://us1.discourse-cdn.com/elastic/original/3X/5/2/527190f370b1e56041c59a7e78c369bcb79688dd.png)

nope still didnt work out.

any idea why

---

<div class="post-metadata">

### Author: ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)
#### Post date: [June 30, 2020, 3:36pm UTC](https://discuss.elastic.co/t/vega-is-not-showing-anything-despite-code-passing-error-free/239142/10 "2020-06-30T15:36:23Z")

</div>

Could you post the JSON code and the error messages? Can't read the screenshots

---

<div class="post-metadata">

### Author: ![Ethan777100](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ethan777100/32/70366_2.png) [@Ethan777100](https://discuss.elastic.co/u/Ethan777100)
#### Post date: [June 30, 2020, 3:38pm UTC](https://discuss.elastic.co/t/vega-is-not-showing-anything-despite-code-passing-error-free/239142/12 "2020-06-30T15:38:35Z")

</div>

```
// Transforms that use field do not use datum (ie joinaggregate)
// But Transforms like calculate do

{
    "$schema": "https://vega.github.io/schema/vega-lite/v2.json",
    "mark": "point",
    "data": {
      "url": {
        "%context%": true,
        "%timefield%": "Arrival_Time",
        "index": "nsew*",
        "body": {
          "size": 10000,
          "_source": ["Current_Platform_Name", "Align_Distance_To_Go_mm","Train_Type"]
        }
      },
      "format": {"property": "hits.hits"}
    },
 "transform": [
 { "filter": "datum._source.Align_Distance_To_Go_mm >= -300 && datum._source.Align_Distance_To_Go_mm <= 300" },
 {
   "joinaggregate": [{
     "op": "count",
     "field": "_source.Align_Distance_To_Go_mm",
     "as": "count_all_Dist"
    }],
    "groupby": ["_source.Current_Platform_Name"]
  },
  {
    "joinaggregate": [{
      "op": "count",
      "field": "_source.Align_Distance_To_Go_mm",
      "as": "count_within_Dist"
    }],
    "groupby": ["_source.Current_Platform_Name"]
    },
   {
    "calculate": " ( datum.count_within_Dist / datum.count_all_Dist)*100 ",
    "as": "Percent_Compliance"
  }
],
    "encoding": {
      "x": {
        "field": "Percent_Compliance",
        "type": "quantitative",
        "axis": {"title": "Percent_Compliance"}
      },
      "y": {
        "field": "_source.Current_Platform_Name",
        "type": "nominal",
        "axis": {"title": "Platform Name"}
      },
      "color": {
        "field": "_source.Current_Platform_Name",
        "type": "nominal",
        "legend": {"title": "Platform Legend"}
      },
      "shape": {"field": "_source.Current_Platform_Name", "type": "nominal"}
    }
  }
```

---

<div class="post-metadata">

### Author: ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)
#### Post date: [June 30, 2020, 4:24pm UTC](https://discuss.elastic.co/t/vega-is-not-showing-anything-despite-code-passing-error-free/239142/13 "2020-06-30T16:24:37Z")

</div>

Okay, here is my recommendation for debugging these transformations- I think they are the cause of the issue, and you should start by removing all transformations and adding them one by one. After each transformation, inspect the `VEGA_DEBUG.view.data('data_0')` to see what it looks like, then iterate. Also, `VEGA_DEBUG.view._runtime.data` contains all the data that is generated internally, but it's a little less useful.

If you are trying to do something like "Count all the documents with this particular condition" then I actually think you should be using Elasticsearch filters instead of Vega filters.

---

<div class="post-metadata">

### Author: ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)
#### Post date: [June 30, 2020, 6:32pm UTC](https://discuss.elastic.co/t/vega-is-not-showing-anything-despite-code-passing-error-free/239142/15 "2020-06-30T18:32:31Z")

</div>

Vega does have a count operator, but your visualization will be much faster if you use the Elasticsearch filters aggregation instead of looking at only 10k docs. Here is how to create a filters aggregation: [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filters-aggregation.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filters-aggregation.html)

Here is an example that is similar to what you're doing:

```auto
{
  $schema: https://vega.github.io/schema/vega-lite/v2.json
  data: {
    url: {
      %context%: true
      %timefield%: @timestamp
     index: metricbeat-*
     body: {
        aggs: {
          categories: {
            terms: { field: "some_category_field", size: 20 }
            aggs: {
              in_or_out: {
                filters: {
                  filters: {
                    in: {
                      range: {
                        "some_number_field": {
                          "gte": -300,
                          "lte": 300
                        }
                      }
                    },
                    out: {
                      bool: {
                        must_not: {
                          range: {
                            "some_number_field": {
                              "gte": -300,
                              "lte": 300
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
        size: 0
      }
    }

    format: {property: "aggregations.categories.buckets"}
  }

  transform: [
    {
      calculate: "datum.in_or_out.buckets.in.doc_count / datum.in_or_out.buckets.out.doc_count",
      as: "percent"
    }
  ]

  mark: bar

  encoding: {
    y: {
      field: "key"
      type: "ordinal"
      sort: {
        field: "percent",
        order: "descending"
        op: "max"
      }
    }
    x: {
      field: "percent"
      type: quantitative
      format: ".2%"
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)
#### Post date: [July 1, 2020, 2:33pm UTC](https://discuss.elastic.co/t/vega-is-not-showing-anything-despite-code-passing-error-free/239142/18 "2020-07-01T14:33:14Z")

</div>

Yes, it's an ES search query.

---

<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: [July 29, 2020, 2:33pm UTC](https://discuss.elastic.co/t/vega-is-not-showing-anything-despite-code-passing-error-free/239142/19 "2020-07-29T14:33:21Z")

</div>

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