abalter
abalter

Reputation: 10383

Plotly hover text not displaying

Although I've specified text and hoverinfo, I'm not getting any hover annotation at all.

If I comment out the "text" attribute, I get the default behavior of hoverinfo: "x+y". I've also tried hoverinfo: "text" and hoverinfo: "x+text" (which is what I really want), but these do not change the behavior.

https://jsfiddle.net/abalter/0cjprqgy/

var data =
{
    "x":["2014-02-10 00:00:00.0","2014-02-18 00:00:00.0","2014-02-24 00:00:00.0"],
  "y":[0,0,0],
  "text":["gemcitabine","gemcitabine + Abraxane","Xeloda"],
  "hoverinfo": "all",
  "name":"Treatment",
  "type":"scatter",
  "mode":"markers",
  "marker":
  {
    "size":9,
    "color":"#800000"
    },
  "uid":"c2e171"
};

var layout = 
{
    "title":"Treatments",
  "height":600,
  "width":655,
  "autosize":true,
  "yaxis":
  {
    "titlefont":
    {
        "size":12,
      "color":"#800000"
    },
    "domain":[0.85,0.9],
    "showgrid":false,
    "showline":false,
    "showticklabels":false,
    "zeroline":true,
    "type":"linear",
    "range":[0,0],
    "autorange":true
  },
  "hovermode":"closest",
  "xaxis":
  {
    "type":"date",
    "range":[1389215256994.8186,1434909143005.1814],
    "autorange":true
  }
};

Plotly.plot('graph', [data], layout);

Upvotes: 4

Views: 6428

Answers (1)

Louys Patrice Bessette
Louys Patrice Bessette

Reputation: 33933

First of all, thank you for having me to discover this really cool graphic platform! I checked at the documentation to get to know how the data has to be formatted (here: https://plot.ly/javascript/hover-events/#coupled-hover-events-on-single-plot)... And "played" with you fiddle.

First, I removed all the unnessessary double quotes you had there, wrapping the param names and placed your value arrays outside of the "data" array. I don't know if it is part of the problem... I just tryed to format it as the example I found.

The "x+y+text" suddenly appeared when I played with the "domain" parameter.
I don't know what it really defines.
I repeat, I have a 10 minutes experience with this thing. (lol)

Check this update I made of your fiddle : https://jsfiddle.net/0cjprqgy/6/

var dates = ["2014-02-10 00:00:00.0","2014-02-18 00:00:00.0","2014-02-24 00:00:00.0"],
  qty = ["0.2","0.5","1"],
  product = ["gemcitabine","gemcitabine + Abraxane","Xeloda"],
data =
{
  x:dates,
  y:qty,
  text:product,
  hoverinfo: "x+y+text",
  name:"Treatment",
  type:"scatter",
  mode:"markers",
  marker:
  {
    size:9,
    color:"#800000"
    },
  uid:"c2e171"
};

var layout = 
{
  title:"Treatments",
  height:600,
  width:655,
  autosize:true,
  yaxis:
  {
    titlefont:
    {
      size:12,
      color:"#800000"
    },
    domain:[0.85,1.9],
    showgrid:false,
    showline:false,
    showticklabels:false,
    zeroline:true,
    type:"linear",
    range:[0,0],
    autorange:true
  },
  hovermode:"closest",
  xaxis:
  {
    type:"date",
    range:[1389215256994.8186,1434909143005.1814],
    autorange:true
  }
};

Plotly.plot('graph', [data], layout);

Upvotes: 4

Related Questions