# Bar Graph Not Showing Up Using Vega

**URL:** https://discuss.elastic.co/t/bar-graph-not-showing-up-using-vega/237321
**Category:** Kibana
**Tags:** vega
**Created:** [June 16, 2020, 2:40pm UTC](https://discuss.elastic.co/t/bar-graph-not-showing-up-using-vega/237321 "2020-06-16T14:40:16Z")
**Posts on this page:** 2
**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 16, 2020, 2:40pm UTC](https://discuss.elastic.co/t/bar-graph-not-showing-up-using-vega/237321/1 "2020-06-16T14:40:17Z")

</div>

Need help with Vega, my bar graph is not showing and i dont get why.

Whilst on the job,

I plan to manipulate "Align\_Distance\_To\_Go\_mm" to extract the counts of the number of its values within +/-300 and assign it to a new variable.

After which, i want to extract the global count of this "Align\_Distance\_To\_Go\_mm" and do a calculate to find the percentage of values within +/-300 classified by "Current\_Platform\_Name"

Pls help me see if my code can improve. Thanks

```auto
    {
      "$schema": "https://vega.github.io/schema/vega-lite/v2.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"}
          }
        }
      ]
    }
```

---

<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 14, 2020, 2:40pm UTC](https://discuss.elastic.co/t/bar-graph-not-showing-up-using-vega/237321/2 "2020-07-14T14:40:22Z")

</div>

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