d3不会将名称空间属性附加到svg元素 [英] d3 doesn't append namespace attributes to svg element

查看:129
本文介绍了d3不会将名称空间属性附加到svg元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么D3.js不会将命名空间属性添加到SVG元素。

I wonder why D3.js doesn't add the namespace attributes to the SVG element.

d3.ns.prefix.ex = 'http://example.com/';
var chart = d3.select('#chart').append('svg:svg');

我认为输出应该是:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:ex="http://example.com/">

其实只是

<svg>

查看这个小提琴的完整示例: http://jsfiddle.net/7kWDK/

See this fiddle for a complete example: http://jsfiddle.net/7kWDK/

推荐答案

命名空间属性仅当文档用作某些XML MIME类型时才相关image / svg + xml。

namespace attributes are only relevant when documents are served as some XML mime type e.g. image/svg+xml.

命名空间在html标记中不做任何操作,如jsfiddle,因此d3不需要创建它们。

namespaces don't do anything in html markup such as jsfiddle so d3 doesn't need to create them.

如果你想要命名空间,那么你可以在html中手动添加属性,或者切换到xhtml,其中将自动创建属性。

If you want namespaces then you could add the attributes manually in html or alternatively switch to xhtml where the attributes will be automatically created.

这篇关于d3不会将名称空间属性附加到svg元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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