# Kibana scatter Plot

**URL:** <https://discuss.elastic.co/t/kibana-scatter-plot/208408>\
**Category:** Kibana\
**Tags:** vega\
**Created:** [November 19, 2019, 12:55am UTC](https://discuss.elastic.co/t/kibana-scatter-plot/208408 "2019-11-19T00:55:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cookie](https://avatars.discourse-cdn.com/v4/letter/c/d26b3c/32.png) [@cookie](https://discuss.elastic.co/u/cookie)\
**Post date:** [November 19, 2019, 12:55am UTC](https://discuss.elastic.co/t/kibana-scatter-plot/208408/1 "2019-11-19T00:55:28Z")

</div>

Hi Guys,

I am trying to have a crack at creating a vega graph from our database. However, for some reason there is is no error in the code but there aren't! If anyone can see if I am missing anything? I've been scratching my head on this one. Thanks in advance!

{  
$schema: [https://vega.github.io/schema/vega-lite/v2.json](https://vega.github.io/schema/vega-lite/v2.json)  
data: {  
# URL object is a context-aware query to Elasticsearch  
url: {  
# The %-enclosed keys are handled by Kibana to modify the query  
# before it gets sent to Elasticsearch. Context is the search  
# filter as shown above the dashboard. Timefield uses the value  
# of the time picker from the upper right corner.  
%context%: true  
%timefield%: timestamp  
index: revitproject-0.0.4\*  
body: {  
size: 10000  
\_source: ["timestamp", "action.duration", "action.name"]  
}  
}  
# We only need the content of hits.hits array  
format: {property: "hits.hits"}  
}

# Parse timestamp into a javascript date value

transform: [  
{calculate: "toDate(datum.\_source['timestamp'])", as: "time"}  
]

# Draw a circle, with x being the time field, and y - number of bytes

mark: circle  
encoding: {  
x: {field: "time", type: "temporal"}  
y: {field: "\_source.action.duration", type: "quantitative"}  
}  
}

[2019-11-15\_1049|690x372](https://discuss.elastic.co/uploads/short-url/5hndkEef5ZDYfR5So0315mhyQ9F.png)

 ![2019-11-15_1049_001](https://us1.discourse-cdn.com/elastic/original/3X/c/d/cd9b9f1d22076bd1413bdd72ae5af14bcc620668.png) any displays?

---

<div class="post-metadata">

**Author:** ![cookie](https://avatars.discourse-cdn.com/v4/letter/c/d26b3c/32.png) [@cookie](https://discuss.elastic.co/u/cookie)\
**Post date:** [November 19, 2019, 3:45am UTC](https://discuss.elastic.co/t/kibana-scatter-plot/208408/2 "2019-11-19T03:45:53Z")

</div>

Ok so I have been, working through the issue line by line and it turns out it might have to with \_source.action.duration

at first, I thought it might have been the index formatting so I changed that to duration format in as second and format output as seconds ... but I still get the same issues.

 ![2019-11-19_1323](https://us1.discourse-cdn.com/elastic/original/3X/f/5/f5e2d1387ab552657b9e1ca4f834e7f00af05172.png)

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [November 19, 2019, 9:43am UTC](https://discuss.elastic.co/t/kibana-scatter-plot/208408/3 "2019-11-19T09:43:35Z")

</div>

Hi @cookie,

Could you follow the steps outlined in this document for your current state: [https://gist.github.com/nyurik/736c34970ba3c32f3fe3d45d66719b3e](https://gist.github.com/nyurik/736c34970ba3c32f3fe3d45d66719b3e)

And attach the results here?

It will inline the data coming from Elasticsearch which makes troubleshooting easier.

---

<div class="post-metadata">

**Author:** ![cookie](https://avatars.discourse-cdn.com/v4/letter/c/d26b3c/32.png) [@cookie](https://discuss.elastic.co/u/cookie)\
**Post date:** [November 29, 2019, 4:26am UTC](https://discuss.elastic.co/t/kibana-scatter-plot/208408/4 "2019-11-29T04:26:11Z")

</div>

hi @flash1293 Joe, Thanks for that tip it does help. I hope the below helps clarify what I am trying to do.

"{"$schema":"[https://vega.github.io/schema/vega/v3.json","autosize":{"type":"fit","contains":"padding"},"padding":5,"style":"cell","data":[{"name":"source\_0","values":{"took":2,"timed\_out":false,"\_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":2,"relation":"eq"},"max\_score":1,"hits":[{"\_index":"revitproject-0.0.4-2019.11","\_type":"\_doc","\_id":"bFlmkm4BdVGWrfNJAFdx","\_score":1,"\_source":{"action.duration":6.633500799999999,"action.name":"Open","timestamp":"2019-11-22T09:16:21.1461782Z"}},{"\_index":"revitproject-0.0.4-2019.11","\_type":"\_doc","\_id":"DFqckm4BdVGWrfNJYo9D","\_score":1,"\_source":{"action.duration":3570.8098565,"action.name":"Closing","timestamp":"2019-11-22T10:15:51.5320006Z"}}]}},"format":{"property":"hits.hits"}},{"name":"data\_0","source":"source\_0","transform":[{"type":"formula","expr":"toNumber](https://vega.github.io/schema/vega/v3.json%22,%22autosize%22:%7B%22type%22:%22fit%22,%22contains%22:%22padding%22%7D,%22padding%22:5,%22style%22:%22cell%22,%22data%22:%5B%7B%22name%22:%22source_0%22,%22values%22:%7B%22took%22:2,%22timed_out%22:false,%22_shards%22:%7B%22total%22:1,%22successful%22:1,%22skipped%22:0,%22failed%22:0%7D,%22hits%22:%7B%22total%22:%7B%22value%22:2,%22relation%22:%22eq%22%7D,%22max_score%22:1,%22hits%22:%5B%7B%22_index%22:%22revitproject-0.0.4-2019.11%22,%22_type%22:%22_doc%22,%22_id%22:%22bFlmkm4BdVGWrfNJAFdx%22,%22_score%22:1,%22_source%22:%7B%22action.duration%22:6.633500799999999,%22action.name%22:%22Open%22,%22timestamp%22:%222019-11-22T09:16:21.1461782Z%22%7D%7D,%7B%22_index%22:%22revitproject-0.0.4-2019.11%22,%22_type%22:%22_doc%22,%22_id%22:%22DFqckm4BdVGWrfNJYo9D%22,%22_score%22:1,%22_source%22:%7B%22action.duration%22:3570.8098565,%22action.name%22:%22Closing%22,%22timestamp%22:%222019-11-22T10:15:51.5320006Z%22%7D%7D%5D%7D%7D,%22format%22:%7B%22property%22:%22hits.hits%22%7D%7D,%7B%22name%22:%22data_0%22,%22source%22:%22source_0%22,%22transform%22:%5B%7B%22type%22:%22formula%22,%22expr%22:%22toNumber)(datum["\_source"] && datum["\_source"]["action"] && datum["\_source"]["action"]["duration"])","as":"\_source.action.duration"},{"type":"formula","expr":"toDate(datum.\_source['timestamp'])","as":"time"},{"type":"filter","expr":"datum["time"] !== null && !isNaN(datum["time"]) && datum["\_source.action.duration"] !== null && !isNaN(datum["\_source.action.duration"])"}]}],"marks":[{"name":"marks","type":"symbol","style":["circle"],"from":{"data":"data\_0"},"encode":{"update":{"opacity":{"value":0.7},"fill":{"value":"#00B3A4"},"x":{"scale":"x","field":"time"},"y":{"scale":"y","field":"\_source\.action\.duration"},"shape":{"value":"circle"}}}}],"scales":[{"name":"x","type":"time","domain":{"data":"data\_0","field":"time"},"range":[0,{"signal":"width"}]},{"name":"y","type":"linear","domain":{"data":"data\_0","field":"\_source\.action\.duration"},"range":[{"signal":"height"},0],"nice":true,"zero":true}],"axes":[{"scale":"x","orient":"bottom","grid":false,"title":"time","labelFlush":true,"labelOverlap":true,"tickCount":{"signal":"ceil(width/40)"},"zindex":1},{"scale":"x","orient":"bottom","grid":true,"tickCount":{"signal":"ceil(width/40)"},"gridScale":"y","domain":false,"labels":false,"maxExtent":0,"minExtent":0,"ticks":false,"zindex":0},{"scale":"y","orient":"left","grid":false,"title":"\_source.action.duration","labelOverlap":true,"tickCount":{"signal":"ceil(height/40)"},"zindex":1},{"scale":"y","orient":"left","grid":true,"tickCount":{"signal":"ceil(height/40)"},"gridScale":"x","domain":false,"labels":false,"maxExtent":0,"minExtent":0,"ticks":false,"zindex":0}],"config":{"axisY":{"minExtent":30},"range":{"category":{"scheme":"elastic"}}}}"

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [December 3, 2019, 11:13am UTC](https://discuss.elastic.co/t/kibana-scatter-plot/208408/5 "2019-12-03T11:13:05Z")

</div>

Hi @cookie,

The problem is that the value you need is in `_source['action.duration']` - that's not the same as `_source.action.duration` because there is a difference that is easy to miss - the first one looks for a key `action.duration` in the `_source` object, the second one for a key `duration` in the `action` object in the `_source` object. For the shape of your data you need the first variant.

I changed your script a bit and it shows two points for me:

```auto
{
  "$schema": "https://vega.github.io/schema/vega/v3.json",
  "width": 500,
  "height": 500,
  "padding": 5,
  "style": "cell",
  "data": [
    {
      "name": "source_0",
      "values": {
        "took": 2,
        "timed_out": false,
        "_shards": {"total": 1, "successful": 1, "skipped": 0, "failed": 0},
        "hits": {
          "total": {"value": 2, "relation": "eq"},
          "max_score": 1,
          "hits": [
            {
              "_index": "revitproject-0.0.4-2019.11",
              "_type": "_doc",
              "_id": "bFlmkm4BdVGWrfNJAFdx",
              "_score": 1,
              "_source": {
                "action.duration": 6.633500799999999,
                "action.name": "Open",
                "timestamp": "2019-11-22T09:16:21.1461782Z"
              }
            },
            {
              "_index": "revitproject-0.0.4-2019.11",
              "_type": "_doc",
              "_id": "DFqckm4BdVGWrfNJYo9D",
              "_score": 1,
              "_source": {
                "action.duration": 3570.8098565,
                "action.name": "Closing",
                "timestamp": "2019-11-22T10:15:51.5320006Z"
              }
            }
          ]
        }
      },
      "format": {"property": "hits.hits"}
    },
    {
      "name": "data_0",
      "source": "source_0",
      "transform": [
        {
          "type": "formula",
          "expr": "toNumber(datum._source['action.duration'])",
          "as": "duration"
        },
        {
          "type": "formula",
          "expr": "toDate(datum._source['timestamp'])",
          "as": "time"
        },
        {
          "type": "filter",
          "expr": "datum['time'] !== null && !isNaN(datum['time']) && datum['duration'] !== null && !isNaN(datum['duration'])"
        }
      ]
    }
  ],
  "marks": [
    {
      "name": "marks",
      "type": "symbol",
      "style": ["circle"],
      "from": {"data": "data_0"},
      "encode": {
        "update": {
          "opacity": {"value": 0.7},
          "fill": {"value": "#00B3A4"},
          "x": {"scale": "x", "field": "time"},
          "y": {"scale": "y", "field": "duration"},
          "shape": {"value": "circle"}
        }
      }
    }
  ],
  "scales": [
    {
      "name": "x",
      "type": "time",
      "domain": {"data": "data_0", "field": "time"},
      "range": [0, {"signal": "width"}]
    },
    {
      "name": "y",
      "type": "linear",
      "domain": {"data": "data_0", "field": "duration"},
      "range": [{"signal": "height"}, 0],
      "nice": true,
      "zero": true
    }
  ],
  "axes": [
    {
      "scale": "x",
      "orient": "bottom",
      "grid": false,
      "title": "time",
      "labelFlush": true,
      "labelOverlap": true,
      "tickCount": {"signal": "ceil(width/40)"},
      "zindex": 1
    },
    {
      "scale": "x",
      "orient": "bottom",
      "grid": true,
      "tickCount": {"signal": "ceil(width/40)"},
      "gridScale": "y",
      "domain": false,
      "labels": false,
      "maxExtent": 0,
      "minExtent": 0,
      "ticks": false,
      "zindex": 0
    },
    {
      "scale": "y",
      "orient": "left",
      "grid": false,
      "title": "_source.action.duration",
      "labelOverlap": true,
      "tickCount": {"signal": "ceil(height/40)"},
      "zindex": 1
    },
    {
      "scale": "y",
      "orient": "left",
      "grid": true,
      "tickCount": {"signal": "ceil(height/40)"},
      "gridScale": "x",
      "domain": false,
      "labels": false,
      "maxExtent": 0,
      "minExtent": 0,
      "ticks": false,
      "zindex": 0
    }
  ],
  "config": {
    "axisY": {"minExtent": 30},
    "range": {"category": {"scheme": "elastic"}}
  }
}

```

---

<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:** [December 31, 2019, 11:13am UTC](https://discuss.elastic.co/t/kibana-scatter-plot/208408/6 "2019-12-31T11:13:07Z")

</div>

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