# Can't display tooltip at all in Vega Pie Chart

**URL:** https://discuss.elastic.co/t/cant-display-tooltip-at-all-in-vega-pie-chart/264056
**Category:** Kibana
**Tags:** vega
**Created:** [February 11, 2021, 9:21pm UTC](https://discuss.elastic.co/t/cant-display-tooltip-at-all-in-vega-pie-chart/264056 "2021-02-11T21:21:40Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Webtrend\_Inc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/webtrend_inc/32/70034_2.png) [@Webtrend\_Inc](https://discuss.elastic.co/u/Webtrend_Inc)
#### Post date: [February 11, 2021, 9:21pm UTC](https://discuss.elastic.co/t/cant-display-tooltip-at-all-in-vega-pie-chart/264056/1 "2021-02-11T21:21:41Z")

</div>

My following vega code correctly displays the actual chart and legend. However, I have been trying to get tooltip to display some data but the tooltips are not showing at all. Here is my latest code

```auto
{
  "$schema": "https://vega.github.io/schema/vega/v4.0.json",
  "title": "Top 10 IP Addresses",
  "data": [
    {
      "name": "table",
      "url": {
        "%context%": "true",
        "%timefield%": "@timestamp",
        "index": "alb-logs-*",
        "body": {
          "aggs": {
            "TopIP": {
              "terms": {
                "field": "elb_client_ip"
              }
            }
          }
        },
        "size": 0
      },
      "format": {
        "property": "aggregations.TopIP.buckets",
        "as": "values"
      },
      "transform": [
        {
          "type": "pie",
          "field": "doc_count"
        }
      ]
    }
  ],
  "legends": [     
    {
      "orient": "top-right",
      "stroke": "color",
      "title": "Origin",
      "encode": {
        "symbols": {
          "update": {
            "fill": {"value": ""},
            "strokeWidth": {"value": 2},
            "size": {"value": 64}
          }
        }
      }
    }
  ],
  "scales": [
    {
      "name": "color",
      "type": "ordinal",
      "domain": {
        "data": "table",
        "field": "key"
      },
      "range": {
        "scheme": "category20"
      }
    }
  ],
  "marks": [
    {
      "type": "arc",
      "from": {
        "data": "table"
      },
      "encode": {
        "enter": {
          "fill": {
            "scale": "color",
            "field": "key"
          },
          "startAngle": {
            "field": "startAngle"
          },
          "endAngle": {
            "field": "endAngle"
          },
          "x": {
            "signal": "width / 2"
          },
          "y": {
            "signal": "height / 2"
          },
          "outerRadius": {
            "signal": "min(width,height)/2.2"
          },
          "tooltip": {"signal": "datum.datum"}
        }
      }
    }
  ]
}

```

What am I missing?

---

<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, 9:33pm UTC](https://discuss.elastic.co/t/cant-display-tooltip-at-all-in-vega-pie-chart/264056/2 "2021-02-11T21:33:01Z")

</div>

Since you haven't provided a [reproduceable data set](https://www.elastic.co/guide/en/kibana/current/vega.html#asking-for-help-with-a-vega-spec) for us to try, it might be that we are going to miss something obvious as well.

That being said, what is the signal `datum.datum`? The value `datum` is bound to the current context of the signal, and you're binding it on `enter`. Maybe you need to fix both your signal reference and the phase of your binding.

> **[Marks](https://vega.github.io/vega/docs/marks/)**
>
> Vega - A Visualization Grammar. Vega is a visualization grammar, a declarative format for creating, saving, and sharing interactive visualization designs. With Vega, you can describe the visual appearance and interactive behavior of a visualization...

> **[Expressions](https://vega.github.io/vega/docs/expressions/)**
>
> Vega - A Visualization Grammar. Vega is a visualization grammar, a declarative format for creating, saving, and sharing interactive visualization designs. With Vega, you can describe the visual appearance and interactive behavior of a visualization...

---

<div class="post-metadata">

### Author: ![Webtrend\_Inc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/webtrend_inc/32/70034_2.png) [@Webtrend\_Inc](https://discuss.elastic.co/u/Webtrend_Inc)
#### Post date: [February 12, 2021, 12:55am UTC](https://discuss.elastic.co/t/cant-display-tooltip-at-all-in-vega-pie-chart/264056/3 "2021-02-12T00:55:01Z")

</div>

@wylie Thanks for your suggestions. I sorted out the issue. I was using wrong field name in tooltip section and as a result the tooltip was not visible.  
One additional question: How do I show percentage value of each slice in the tooltip? I presume it requires some kind of mathematical transform to compute based on the total number of docs for a given aggregate bucket but my Vega grammar knowledge is extremely poor and I am struggling. Is there an example of this anywhere?

---

<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 12, 2021, 5:20pm UTC](https://discuss.elastic.co/t/cant-display-tooltip-at-all-in-vega-pie-chart/264056/4 "2021-02-12T17:20:14Z")

</div>

I've never seen an example, but isn't that something you can calculated based on the `pie` transform? You could probably take `(datum.endAngle - datum.startAngle) / (2 * PI)` as your percentae.

---

<div class="post-metadata">

### Author: ![Webtrend\_Inc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/webtrend_inc/32/70034_2.png) [@Webtrend\_Inc](https://discuss.elastic.co/u/Webtrend_Inc)
#### Post date: [February 13, 2021, 3:42am UTC](https://discuss.elastic.co/t/cant-display-tooltip-at-all-in-vega-pie-chart/264056/5 "2021-02-13T03:42:05Z")

</div>

Excellent solution. I ended up with an expression like this  
`"tooltip": {"signal": "'IP: '+ datum['key']+', Count: '+ datum['doc_count'] + ' Share: '+ ceil(((datum['endAngle']-datum['startAngle'])/(2*PI))*100) + '%'"}`

---

<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 13, 2021, 6:44pm UTC](https://discuss.elastic.co/t/cant-display-tooltip-at-all-in-vega-pie-chart/264056/6 "2021-02-13T18:44:11Z")

</div>

You could also use the `format` function to do something like `format(value, '.2%')` if I remember the syntax correctly. It's using d3-format internally.

---

<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 13, 2021, 6:45pm UTC](https://discuss.elastic.co/t/cant-display-tooltip-at-all-in-vega-pie-chart/264056/7 "2021-03-13T18:45:09Z")

</div>

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