Plotly: How can I change the format of hover-on labels?

拥有回忆 提交于 2019-12-04 13:19:13

问题


I've looked through online documentation, but couldn't find how to change the format of hover-on labels:

For example, if I'd like to display the number as "~611 thousand" or something of the sort.


回答1:


Plotly tick and hover formatting are fully customizable using the python / d3 formatting language.

From an API, use axis attributes 'tickformat' and 'hoverformat' to set the behavior. For example, this graph has 'layout.yaxis.hoverformat': ',f'.

From the web app, input your formatting specs under "Axes" -> "Labels":




回答2:


Plotly allows for axis and hover format only String values, so you cant write your own function to format labels with such unusual style.

So I see only one solution -- change created hover tooltip using jquery and "on_hover" event:

result.on('plotly_hover', function (eventdata){
  /*
   * var hoverTooltip = $(".hovertext", result)[0],
   *     hoverText = $("text", hoverTooltip).get(0),
   *     hoverFrame = $("path", hoverTooltip).get(0);
   *
   *  do what you want here
   *
   */
})

But it's a lot of work here (you must take into account size and position of the hover tooltip also)



来源:https://stackoverflow.com/questions/30666214/plotly-how-can-i-change-the-format-of-hover-on-labels

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!