# Tooltip in Vega

**URL:** https://discuss.elastic.co/t/tooltip-in-vega/263886
**Category:** Kibana
**Created:** [February 10, 2021, 3:12pm UTC](https://discuss.elastic.co/t/tooltip-in-vega/263886 "2021-02-10T15:12:46Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Pranath](https://avatars.discourse-cdn.com/v4/letter/p/4da419/32.png) [@Pranath](https://discuss.elastic.co/u/Pranath)
#### Post date: [February 10, 2021, 3:12pm UTC](https://discuss.elastic.co/t/tooltip-in-vega/263886/1 "2021-02-10T15:12:46Z")

</div>

Here I wanted to show distinct 'd' field values for each 'a' field in tooltip. For text it's giving correct but A and B are overlapping and in tooltip it's giving only B.

```auto
{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "description": "A simple bar chart with embedded data with tooltip.",
  "width":500,
  "height":300,
  "data": {
    "values": [
      {"a": "A", "b": 28,"d": "A"},
      {"a": "A", "b": 55,"d": "A"},
      {"a": "A", "b": 43,"d": "B"},
      {"a": "A", "b": 91,"d": "B"},
      {"a": "B", "b": 81,"d": "A"},
      {"a": "B", "b": 53,"d": "A"},
      {"a": "G", "b": 19,"d": "B"},
      {"a": "H", "b": 87,"d": "A"},
      {"a": "I", "b": 52,"d": "B"}
    ]
  },
   "encoding": {
    "x": {"field": "a", "type": "nominal"}
  },
  "layer":[

{
     "encoding": {
       "y": {"aggregate":"distinct", "field": "d",
          "scale": {"domain": [0, 10]},
          "type": "quantitative", 
          "title": "Open Rate (%)",
          "axis": {"titleColor":"#54b399"}
        }
      },
  "layer":[{
    "mark": {"stroke": "#54b399", "type": "line", "interpolate": "monotone", "point": true}
 
    },
     {
    "mark": {
      "type": "text",
      "align": "left",
      "baseline": "middle",
     "fontSize": 24,
      "dx": 3,
      "dy": -13
    },
    "encoding": {
      "text": {"field": "d"},
    "tooltip": {"field": "d"}

    }
  }
    ]
    } ],
  "resolve": {"scale": {"y": "independent"}} 

}

```

![image](https://us1.discourse-cdn.com/elastic/original/3X/d/8/d83b1866ba7db5a69fae83ba70bf6133a7d7c1b1.png)

can I know how to get both A and B values in tooltip ?

---

<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: [February 10, 2021, 3:47pm UTC](https://discuss.elastic.co/t/tooltip-in-vega/263886/2 "2021-02-10T15:47:40Z")

</div>

You need to apply your `distinct` aggregation inside a transform function _before the encoding_. What your spec shows is that you are _only getting distinct data for the first layer_, and the second layer is getting all the data.

---

<div class="post-metadata">

### Author: ![Pranath](https://avatars.discourse-cdn.com/v4/letter/p/4da419/32.png) [@Pranath](https://discuss.elastic.co/u/Pranath)
#### Post date: [February 11, 2021, 4:45am UTC](https://discuss.elastic.co/t/tooltip-in-vega/263886/3 "2021-02-11T04:45:09Z")

</div>

Hi @wylie

I added transform before encoding, when I added the field d in tooltip it's giving undefined.

```auto
{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "description": "A simple bar chart with embedded data with tooltip.",
  "width":500,
  "height":300,
  "data": {
    "values": [
      {"a": "A", "b": 28,"d": "A"},
      {"a": "A", "b": 55,"d": "A"},
      {"a": "A", "b": 43,"d": "B"},
      {"a": "A", "b": 91,"d": "B"},
      {"a": "B", "b": 81,"d": "A"},
      {"a": "B", "b": 53,"d": "A"},
      {"a": "G", "b": 19,"d": "B"},
      {"a": "H", "b": 87,"d": "A"},
      {"a": "I", "b": 52,"d": "B"}
    ]
  },
  "transform":[    
  {
        "aggregate": [
        {"op": "distinct", "field": "d","as": "a_count"}
        ],
        "groupby": ["a"]
      }
      ],
     "encoding": {
     "x": {"field": "a", "type": "nominal"},
       "y": {"field": "a_count",
          "scale": {"domain": [0, 10]},
          "type": "quantitative", 
          "title": "Open Rate (%)",
          "axis": {"titleColor":"#54b399"}
        },
          
      },
  "layer":[{
    "mark": {"stroke": "#54b399", "type": "line", "interpolate": "monotone", "point": true}
 
    },
     {
    "mark": {
      "type": "text",
      "align": "left",
      "baseline": "middle",
     "fontSize": 24,
      "dx": 3,
      "dy": -13
    },
    "encoding": {
      "text": {"field": "d"},
      "tooltip":{"field":"d"}
    

    }
  }
    ]

}

```

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

---

<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: [February 11, 2021, 4:22pm UTC](https://discuss.elastic.co/t/tooltip-in-vega/263886/4 "2021-02-11T16:22:03Z")

</div>

I would be able to help more if this was related to an Elasticsearch query, but I think the problem is the sample data you're using.

---

<div class="post-metadata">

### Author: ![Pranath](https://avatars.discourse-cdn.com/v4/letter/p/4da419/32.png) [@Pranath](https://discuss.elastic.co/u/Pranath)
#### Post date: [February 11, 2021, 5:16pm UTC](https://discuss.elastic.co/t/tooltip-in-vega/263886/5 "2021-02-11T17:16:13Z")

</div>

Hi @wylie

I am not sure if there is any problem with sample data, I was getting result as undefined with the main data I was using.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/a/4/a409206d0692f6470fd7133d843db6a01b0bc344.png)

---

<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: [February 11, 2021, 5:27pm UTC](https://discuss.elastic.co/t/tooltip-in-vega/263886/6 "2021-02-11T17:27:38Z")

</div>

Are you building a Vega spec based on Elasticsearch data? If so, can you please share the raw spec and the spec with data? [Vega | Kibana Guide [7.11] | Elastic](https://www.elastic.co/guide/en/kibana/current/vega.html#asking-for-help-with-a-vega-spec)

---

<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: [March 11, 2021, 5:28pm UTC](https://discuss.elastic.co/t/tooltip-in-vega/263886/7 "2021-03-11T17:28:19Z")

</div>

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