custom a tooltipContent of tooltips with datum in discreteBarChart nvd3.js

不羁岁月 提交于 2019-12-01 03:34:37

This is how to do it:

nv.addGraph(function() {  
   var chart = nv.models.discreteBarChart()
      .x(function(d) { return d.Data1 })
      .y(function(d) { return d.Data2 })
      .tooltips(true)
      .tooltipContent(function(key, y, e, graph) {
       var data =graph.series.values[y-1];
       return  '<p> Text1: ' +  data.Data3 + '</p>'
             + '<p> Text2: ' +  data.Data4 + '</p>'
             + '<p> Text3: ' +  data.Data5 + '</p>'
       });

   d3.select('#chart svg')
      .datum(JsonData)
      .call(chart);

   nv.utils.windowResize(chart.update);

   return chart;
});
xJREB

I came up with something like this, since the graph object has a value attribute:

chart.tooltipContent(function (key, date, e, graph) {
     var value = graph.value;
     return  "<p><strong>" + date + "</strong><br>" + value + "</p>";
});

No need for accessing the series-array I guess.

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