# Axis hover formatting with function

**URL:** <https://community.plotly.com/t/axis-hover-formatting-with-function/1349>\
**Category:** plotly.js\
**Created:** [June 21, 2016, 5:16am UTC](https://community.plotly.com/t/axis-hover-formatting-with-function/1349 "2016-06-21T05:16:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![eagor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/eagor/32/424_2.png) [@eagor](https://community.plotly.com/u/eagor)\
**Post date:** [June 21, 2016, 5:16am UTC](https://community.plotly.com/t/axis-hover-formatting-with-function/1349/1 "2016-06-21T05:16:03Z")

</div>

I have a date x axis, and I need to show DAY or NIGHT on hover, instead of actual date. I can’t achieve it with d3 time formatting string.  
Would be great to be able to pass a function, that would calculate the hover text based on the x value, ie:  
`layout.xaxis.hoverformat: function(date) { // determinte DAY, NIGHT, whatever from the date; }`

---

<div class="post-metadata">

**Author:** ![etienne](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/etienne/32/17_2.png) [@etienne](https://community.plotly.com/u/etienne)\
**Post date:** [June 21, 2016, 4:32pm UTC](https://community.plotly.com/t/axis-hover-formatting-with-function/1349/2 "2016-06-21T16:32:54Z")

</div>

plotly.js attempts to make every chart attribute JSON serializable, that is custom functions won’t be part of our API for the foreseeable future.

Here are two possible workarounds:

- use `tickvals` and `ticktext` to customize the axis labels: [http://codepen.io/etpinard/pen/mEOVad](http://codepen.io/etpinard/pen/mEOVad)
- use trace `text` and `hoverinfo` to customize the hover labels: [http://codepen.io/etpinard/pen/BzQjMz](http://codepen.io/etpinard/pen/BzQjMz)

---

<div class="post-metadata">

**Author:** ![eagor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/eagor/32/424_2.png) [@eagor](https://community.plotly.com/u/eagor)\
**Post date:** [June 21, 2016, 11:28pm UTC](https://community.plotly.com/t/axis-hover-formatting-with-function/1349/3 "2016-06-21T23:28:32Z")

</div>

Thank you.  
Customizing hover values seems like a solution for me. But I have grouped bar chart, and getting same hover for every trace.

Is there a way to have single hover for a whole group?

---

<div class="post-metadata">

**Author:** ![etienne](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/etienne/32/17_2.png) [@etienne](https://community.plotly.com/u/etienne)\
**Post date:** [June 23, 2016, 4:35pm UTC](https://community.plotly.com/t/axis-hover-formatting-with-function/1349/4 "2016-06-23T16:35:56Z")

</div>

> [@eagor](#):
>
> Is there a way to have single hover for a whole group?

Not at the moment. Hover labels are generated per trace.
