如何像列表一样显示SVG标题内容,而不是直线

发布于 2025-01-21 02:57:56 字数 1015 浏览 3 评论 0原文

我正在使用SVG创建离散的传奇,在该传说中,我将标题附加到rect上,以显示悬停的内容,但标题的内容以直线显示,我想一个又一个又一个类似的列表。例如:内容1第一行内容2,依此类推。

代码段的一部分:

//有一个我正在附加的div svg

<div id="legend" ref={divRef}></div>
const currentDiv = select(divRef.current);

// creating svg
currentDiv
.append("svg")
.attr("viewBox", `0 0 ${count} 1`)
.attr("preserveAspectRatio", "none")

g.selectAll("g.legendCells")
.data(data)
.enter()
.append("g")
.append("rect")
.append("title")
.append("span")
.text(legendValues) // this is title content (array items)

//i.sstatic.net/9Mygg.png“ alt =” inter taimy Description在此处“>

fiddle链接: https://jsfiddle.net/r4lafyjs/

基本上标题是阵列值,例如格式:

0: "Content_0"
1: "Content_1"
2: "Content_2"
3: "Content_3"

必须显示在悬停在rect cell上,索引:content:content

I am creating discrete legend using SVG, where I am appending title to the rect to show content on hover but the content of title is displayed in straight line, which I want to come one after the other like list. Ex: Content 1 first and next line Content 2 and so on.

Part of Code Snippet:

// Have a div for which I am appending the svg

<div id="legend" ref={divRef}></div>
const currentDiv = select(divRef.current);

// creating svg
currentDiv
.append("svg")
.attr("viewBox", `0 0 ${count} 1`)
.attr("preserveAspectRatio", "none")

g.selectAll("g.legendCells")
.data(data)
.enter()
.append("g")
.append("rect")
.append("title")
.append("span")
.text(legendValues) // this is title content (array items)

enter image description here

Fiddle link : https://jsfiddle.net/r4Lafyjs/

Basically the title is array values like in format :

0: "Content_0"
1: "Content_1"
2: "Content_2"
3: "Content_3"

Which must be shown on hover over the rect cells, index: content

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文