# Simple Scatter Plot - Vega Lite

**URL:** <https://discuss.elastic.co/t/simple-scatter-plot-vega-lite/233169>\
**Category:** Kibana\
**Tags:** vega\
**Created:** [May 18, 2020, 5:48pm UTC](https://discuss.elastic.co/t/simple-scatter-plot-vega-lite/233169 "2020-05-18T17:48:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dilzeem](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dilzeem/32/68573_2.png) [@dilzeem](https://discuss.elastic.co/u/dilzeem)\
**Post date:** [May 18, 2020, 5:48pm UTC](https://discuss.elastic.co/t/simple-scatter-plot-vega-lite/233169/1 "2020-05-18T17:48:39Z")

</div>

I am trying to create a simple scatter plot, using vega lite.  
I have tried a few different scenarios, and they all seem to be failing.

First one is something like this

```auto
    {
      $schema: https://vega.github.io/schema/vega-lite/v2.json
      title: Scatter
      data: {
        url: {
          %context%: true
          index: notes
          body: {
            size: 5
            _source: ["x", "y"]
          }
          format: {property: "hits.hits"}
        }
      }
          
      mark: point
      encoding: {
        time: {field: "x", type: "quantitative"}
        y: {field: "y", type: "quantitative"}
      }
    }

```

OR

```auto
   {
      $schema: https://vega.github.io/schema/vega-lite/v2.json
      title: Scatter
      data: {
        url: {
          %context%: true
          index: notes
          body: {
            size: 5
            _source: ["x", "y"]
          }
          format: {property: "hits.hits"}
        }
      }
          
      mark: point
      encoding: {
        time: {field: "_source.x", type: "quantitative"}
        y: {field: "_source.y", type: "quantitative"}
      }
    }

```

What I get here is an empty graph. No Error message at all.

When I make the query in the dev console:

```auto
    GET notes/_search
    { "size": 5,
      "_source": ["x","y"]
    }

```

I get:

```auto
    {
      "took" : 9,
      "timed_out" : false,
      "_shards" : {
        "total" : 5,
        "successful" : 5,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : {
          "value" : 10000,
          "relation" : "gte"
        },
        "max_score" : 1.0,
        "hits" : [
          {
            "_index" : "notes",
            "_type" : "_doc",
            "_id" : "ggGQKHIBI40J2F7INuEv",
            "_score" : 1.0,
            "_source" : {
              "x" : 7.0823164000000025,
              "y" : 0.65225583
            }
          },
          {
            "_index" : "notes",
            "_type" : "_doc",
            "_id" : "gwGQKHIBI40J2F7INuEv",
            "_score" : 1.0,
            "_source" : {
              "x" : 17.834715,
              "y" : 0.045098975
            }
          }, ........

```

So I would expect the values to show up.

When i run the following in the console  
https://gist.github.com/nyurik/736c34970ba3c32f3fe3d45d66719b3e

I get:

```auto
{
    "autosize": {
        "contains": "padding",
        "type": "fit"
    },
    "config": {
        "mark": {
            "color": "#00B3A4"
        },
        "range": {
            "category": {
                "scheme": "elastic"
            }
        }
    },
    "encoding": {
        "y": {
            "type": "quantitative",
            "field": "y"
        },
        "time": {
            "type": "quantitative",
            "field": "x"
        }
    },
    "mark": "point",
    "data": {
        "values": {
            "hits": {
                "hits": [
                    {
                        "_source": {
                            "y": 0.65225583,
                            "x": 7.0823164000000025
                        },
                        "_score": 0,
                        "_id": "ggGQKHIBI40J2F7INuEv",
                        "_type": "_doc",
                        "_index": "notes"
                    },
                    {
                        "_source": {
                            "y": 0.045098975,
                            "x": 17.834715
                        },
                        "_score": 0,
                        "_id": "gwGQKHIBI40J2F7INuEv",
                        "_type": "_doc",
                        "_index": "notes"
                    },
                    {
                        "_source": {
                            "y": 14.779006,
                            "x": -9.685422
                        },
                        "_score": 0,
                        "_id": "hQGQKHIBI40J2F7INuEv",
                        "_type": "_doc",
                        "_index": "notes"
                    },
                    {
                        "_source": {
                            "y": 0.5968291,
                            "x": 18.18041
                        },
                        "_score": 0,
                        "_id": "iAGQKHIBI40J2F7INuEv",
                        "_type": "_doc",
                        "_index": "notes"
                    },
                    {
                        "_source": {
                            "y": 12.066802,
                            "x": -1.1508789
                        },
                        "_score": 0,
                        "_id": "kQGQKHIBI40J2F7INuEv",
                        "_type": "_doc",
                        "_index": "notes"
                    }
                ],
                "max_score": 0,
                "total": {
                    "relation": "gte",
                    "value": 10000
                }
            },
            "_shards": {
                "failed": 0,
                "skipped": 0,
                "successful": 5,
                "total": 5
            },
            "timed_out": false,
            "took": 1
        }
    },
    "title": "Event counts from all indexes",
    "$schema": "https://vega.github.io/schema/vega-lite/v2.json"
}

```

---

<div class="post-metadata">

**Author:** ![lukeelmers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukeelmers/32/35230_2.png) [@lukeelmers](https://discuss.elastic.co/u/lukeelmers)\
**Post date:** [May 18, 2020, 8:13pm UTC](https://discuss.elastic.co/t/simple-scatter-plot-vega-lite/233169/2 "2020-05-18T20:13:19Z")

</div>

Hi @dilzeem,

`format` needs to live outside of your `url` object. See if this works:

```auto
   {
      $schema: https://vega.github.io/schema/vega-lite/v2.json
      title: Scatter
      mark: point
      data: {
        url: {
          %context%: true
          index: notes
          body: {
            size: 5
            _source: ["x", "y"]
          }
        }
        format: {property: "hits.hits"}
      }
      encoding: {
        time: {field: "_source.x", type: "quantitative"}
        y: {field: "_source.y", type: "quantitative"}
      }
    }

```

---

<div class="post-metadata">

**Author:** ![dilzeem](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dilzeem/32/68573_2.png) [@dilzeem](https://discuss.elastic.co/u/dilzeem)\
**Post date:** [May 19, 2020, 8:15am UTC](https://discuss.elastic.co/t/simple-scatter-plot-vega-lite/233169/3 "2020-05-19T08:15:56Z")

</div>

Doh,

Thanks for that!! It works now.

---

<div class="post-metadata">

**Author:** ![timroes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timroes/32/19712_2.png) [@timroes](https://discuss.elastic.co/u/timroes)\
**Post date:** [May 19, 2020, 10:12am UTC](https://discuss.elastic.co/t/simple-scatter-plot-vega-lite/233169/4 "2020-05-19T10:12:42Z")

</div>

It might also make sense using `encoding.x` instead of `encoding.time` since you're using a quantitative field not a time field for it. Most likely it will also work, but I am not sure if there might not be some weird side-effects of using `time` like you did.

---

<div class="post-metadata">

**Author:** ![dilzeem](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dilzeem/32/68573_2.png) [@dilzeem](https://discuss.elastic.co/u/dilzeem)\
**Post date:** [May 19, 2020, 10:37am UTC](https://discuss.elastic.co/t/simple-scatter-plot-vega-lite/233169/5 "2020-05-19T10:37:40Z")

</div>

Thanks.

Yeah I think that was a typo from a previous attempt at debugging what was going.

But just to take this further. Are we able from this example to select a region in the scatter plot. Then with those selected values trigger updates to the rest of the dashboard.

Similar to `%context%: true` but from vega-lite/vega back the other way.

---

<div class="post-metadata">

**Author:** ![lukeelmers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukeelmers/32/35230_2.png) [@lukeelmers](https://discuss.elastic.co/u/lukeelmers)\
**Post date:** [May 19, 2020, 5:29pm UTC](https://discuss.elastic.co/t/simple-scatter-plot-vega-lite/233169/6 "2020-05-19T17:29:16Z")

</div>

Yes, you can use `kibanaAddFilter` in your signal handlers to do this. More info is available [in the original PR](https://github.com/elastic/kibana/pull/17586), and a more complete example [in this gist](https://gist.github.com/nyurik/3c579fb8e81c8a981d4b267ad1767227).

The only caveat with these right now is that they'll only work with the default index pattern. There is [an open issue](https://github.com/elastic/kibana/issues/56833) for fixing this bug so that non-default index patterns can be used as well.

---

<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:** [June 16, 2020, 5:29pm UTC](https://discuss.elastic.co/t/simple-scatter-plot-vega-lite/233169/7 "2020-06-16T17:29:17Z")

</div>

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