是否可以使用d3.js没有html通过clear svg? [英] Is it possible to use d3.js without html by clear svg?
问题描述
如何直接在svg文件中导入D3.js脚本?
How can I import D3.js script directly in svg file?
我试试这个
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
但是在同一个文件的另一个脚本中使用d3.select和其他d3函数的代码不工作,我在浏览器中打开svg文件
but code using d3.select and other d3 functions in another script in the same file doesnt work, when I open svg file in browser
推荐答案
您可以将脚本嵌入独立的SVG文件,但语法与HTML不同。
You can embed scripts in stand-alone SVG files, but the syntax is different from HTML.
对于嵌入式脚本,主要区别是您必须将代码包装在XMLCDATA块中:
For embedded scripts, the main difference is that you have to wrap your code in an XML "CDATA" block:
<script type="application/ecmascript">
<![CDATA[ /*script goes here*/]]>
</script>
对于外部脚本,您可以指定 xlink:href
,不是 src
:
For external scripts, you specify the url with xlink:href
, not src
:
<script type="application/ecmascript" xlink:href="sample.es"/>
另一个区别,你可以看到,它们是指定的脚本类型。但是,类型规范是可选的,因为默认为ECMAScript(标准Javascript)。
The other difference, as you can see, is they way the type of script is specified. However, the type specification is optional as ECMAScript (standard Javascript) is the default.
这篇关于是否可以使用d3.js没有html通过clear svg?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!