# Adding customdata to hovertemplate containing a json for each data point

**URL:** https://community.plotly.com/t/adding-customdata-to-hovertemplate-containing-a-json-for-each-data-point/49619
**Category:** plotly.js
**Created:** [February 2, 2021, 12:03am UTC](https://community.plotly.com/t/adding-customdata-to-hovertemplate-containing-a-json-for-each-data-point/49619 "2021-02-02T00:03:34Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![bbiney1](https://avatars.discourse-cdn.com/v4/letter/b/7c8e57/32.png) [@bbiney1](https://community.plotly.com/u/bbiney1)
#### Post date: [February 2, 2021, 12:03am UTC](https://community.plotly.com/t/adding-customdata-to-hovertemplate-containing-a-json-for-each-data-point/49619/1 "2021-02-02T00:03:34Z")

</div>

I’m trying to do something very similar to what’s talked about in this github issue and linked in the following comment - [Not possible to use several customdata values per data points in go.Pie · Issue #4591 · plotly/plotly.js · GitHub](https://github.com/plotly/plotly.js/issues/4591#issuecomment-589832329)

The difference is just, rather than storing an array in customdata to get that associated with each data point, I want to know if it’s possible to store a json/javascript object as each row of the customdata variable, rather than a 1 d array like what’s included here.

I want to get this to work with customdata looking like the following:

```auto
customdata": [
        { 
          foo: "a",
          bar: "A"
        },{ 
          foo: "b",
          bar: "B"
        },{ 
          foo: "c",
          bar: "C"
        },{ 
          foo: "d",
          bar: "D"
        }
          
        ],

```

But if I change customdata to the above, I can’t figure out how to access the customdata object at a specified field despite how many edits I keep trying.

```auto
 "hovertemplate": "foo:%{customdata[0]['foo']} <br> bar:%{customdata[0]['bar']}", // shows "customdata[0]['foo']" as a string in tooltip, doesn't evaluate expression

```

---

<div class="post-metadata">

### Author: ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)
#### Post date: [February 2, 2021, 1:02pm UTC](https://community.plotly.com/t/adding-customdata-to-hovertemplate-containing-a-json-for-each-data-point/49619/2 "2021-02-02T13:02:48Z")

</div>

@bbiney1

Your adopted solution to display customdata is not the right one, because `customdata[0]` is interpreted by plotly.js as the given `customdata`, and `customdata["foo"]` has no sense (plotly.py displays the error: `invalid syntax`).

To get a working customdata, define from your list of dicts, the following array:

```auto
newcustomdata= [['a', 'A'],
                ['b', 'B'],
                ['c', 'C'],
                ['d', 'D']]

```

and set in the trace definition:

```auto
customdata=newcustomdata,
hovertemplate ="foo: %{customdata[0]}<br>bar: %{customdata[1]}"

```

---

<div class="post-metadata">

### Author: ![Victor\_Aguirre](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/victor_aguirre/32/31924_2.png) [@Victor\_Aguirre](https://community.plotly.com/u/Victor_Aguirre)
#### Post date: [June 20, 2025, 10:58pm UTC](https://community.plotly.com/t/adding-customdata-to-hovertemplate-containing-a-json-for-each-data-point/49619/3 "2025-06-20T22:58:26Z")

</div>

the problem I am having is that I cannot add the data point by point, I am trying the following:

“customdatasrc”: [  
“username”,  
“risk”  
],

when I add this to a hover tooltip, it shows me all the usernames for each of the points, not just the username that belongs to a particular point. I get that you would need to add it like a dictionary, but I can’t figure out how to do this
