簡體   English   中英

鼠標懸停事件中 D3.js 中的行返回

[英]Line return in D3.js in a mouseover event

我正在嘗試在 D3.js 可視化中構建我的 output 並且我正在使用 \n 行返回,但 JS 沒有讀取它,關於如何解決它的任何想法?

非常感謝您提前:)

.on('mousemove', function(d) {
    tooltip
      .style('top', d3.event.pageY - 10 + 'px')
      .style('left', d3.event.pageX + 10 + 'px')
      .text(`Number of clones in the class: ${d.data.value/2}   \r\n \n \r
             Code of the class: ${d.data.code}
             Lines at which the clone appears:  ${d.data.lines}`);
    })

您可以對每個新行使用tspan並使用dy屬性來獲取行高

.on('mousemove', function(d) {
    tooltip
      .style('top', d3.event.pageY - 10 + 'px')
      .style('left', d3.event.pageX + 10 + 'px')
      .html(`<tspan x='0' dy='1.2em'>Number of clones in the class: ${d.data.value/2}</tspan>
             <tspan x='0' dy='1.2em'>Code of the class: ${d.data.code}</tspan>
            <tspan x='0' dy='1.2em'>Lines at which the clone appears:  ${d.data.lines}</tspan>`);
    })

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM