简体   繁体   English

d3-tip-在工具提示中创建标题的问题

[英]d3-tip - problems with creating a title in a tooltip

I've successfully created a chart in a tooltip, by following this example: https://bl.ocks.org/maelafifi/ee7fecf90bb5060d5f9a7551271f4397 . 通过遵循以下示例,我已经在工具提示中成功创建了图表: https : //bl.ocks.org/maelafifi/ee7fecf90bb5060d5f9a7551271f4397 But my problem is in creating a title, like so: 但是我的问题是创建标题,如下所示:

var tool_tip = d3.tip()
            .attr("class", "d3-tip")
            .offset([10, -50])
            .html(function(d){console.log(d); return "<p> Day: and hour:</p><div id='tipDiv'></div>";});
            //.html(function(d,i){console.log(d); return "<p>Distribution for all weeks at: Day: " + d.day + " and hour: " + d.hour +"</p><div id='tipDiv'></div>";}); 
            svg_sum.call(tool_tip);

I actually want to create the text that is commented out, but when looking in the console, it says that d is undefined. 我实际上想创建注释掉的文本,但是在控制台中查看时,它说d是未定义的。 Additionally, I would like to use the information in d to offset the tooltip. 另外,我想使用d中的信息来抵消工具提示。 My attempt can be seen here: http://bl.ocks.org/skov94/0c4befd23bcaeacb85c18c7a5484f95d 我的尝试可以在这里看到: http : //bl.ocks.org/skov94/0c4befd23bcaeacb85c18c7a5484f95d

In your code, you have an argument d which you might have forgotten to pass in. 在您的代码中,您有一个可能忘记传递的参数d

So, when calling the function, do something like: 因此,在调用函数时,请执行以下操作:

tool_tip.show(day)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM