可以在D3中实现SVG模式吗? [英] Can an SVG pattern be implemented in D3?

查看:194
本文介绍了可以在D3中实现SVG模式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试过:

var pattern = d3.select("#container").append("svg:pattern");
pattern.append("svg:defs") ... //and so on

但在append("svg:pattern")上遇到错误,因此我认为d3中尚未实现.

but ran into errors on append("svg:pattern") so I assume that is not implemented in d3 yet.

我的解决方案是在d3之外简单地运行SVG代码,因为我不需要d3的强大功能,所以效果很好. (我意识到我可以将.data(dataset)附加到SVG对象上并遍历该对象来创建它,但是这完全是d3的工作,无缘无故.)

My solution was to simply run the SVG code outside of d3 which worked fine since I did not need the power of d3 for this piece. (I realized I could have attached a .data(dataset) to an SVG object and looped through it to create it, but that would have been a lot of d3 effort for no reason.)

这是一个健全性检查问题:在d3中尝试实现svg模式时是否错过了某些东西,还是我的解决方案是正确的方法?

This is a sanity-check question: Did I miss something in trying to implement an svg pattern in d3, or was my solution the correct approach?

(感谢您 Mike Bostock 这样一个令人难以置信的图书馆.)

(Thank you Mike Bostock for such an incredible library.)

推荐答案

D3或多或少与您不熟悉它有关-您可以生成SVG,HTML等.没有理由为什么SVG模式不起作用.从您发布的小代码中,您似乎正在尝试将模式附加到HTML元素.在开始定义模式之前,您必须先创建SVG和defs元素.

D3 is more or less agnostic to what you're dong with it -- you can generate SVG, HTML, whatever. There's no reason why SVG patterns wouldn't work. From the little code you've posted it looks like you might be trying to append the pattern to an HTML element. You'll have to create the SVG and the defs element before starting to define the pattern.

这篇关于可以在D3中实现SVG模式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆