d3.js - 使用 D3 在 ie8 上渲染 map

标签 d3.js internet-explorer-8 raphael

我知道 D3 不支持 IE8,但我希望找到可以工作的东西。

我正在尝试使用 R2D3 https://github.com/mhemesath/r2d3 ,但我正在创建的 map 仍未呈现。在页面头部加载 r2d2 后,我有:

projection = d3.geo.albersUsa()
  .scale(700)
  .translate([1000*0.3, 400*0.4])

path = d3.geo.path()

mapData = topojson.features(mapJSON, mapJSON.objects.states)

d3.select('svg')
  .append('path')
  .attr('class', 'states')
  .datum(mapData)
  .attr('d', path.projection(projection))

这在 chrome 中呈现良好,但在 ie8 中它不起作用。

使用 r2d3 渲染

<svg width="675" height="290">
    <path class="states" __data__='[object object]' d="
</svg>

所以看起来 path.projection(projection) 的回调实际上并没有被执行或者没有返回任何东西。从而制动 html。

此外,我的印象是 r2d3 会在 ie8 中降级为非 svg 元素。

谁有在ie8中渲染d3 map 的经验?

我看过 Making d3.js compatible with IE8/IE9 , https://github.com/mbostock/d3/issues/619等等。

最佳答案

IE8 不支持 svg,那是 IE9 才开始的。我既不知道 D3 也不知道 r2d3,但我可以为您做的是建议使用 http://raphaeljs.com/

这是一个非常棒的 JS 库,可满足多种需求,它通过浏览器检测在 IE8 VML 而不是 SVG 中呈现。

如果您在使用 RaphaelJS 时需要任何帮助,请评论此答案并提供更多关于您的 map 数据以及您希望如何处理的信息。

最好的问候。

关于d3.js - 使用 D3 在 ie8 上渲染 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24619996/

相关文章:

javascript - javascript参数背后的概念是什么?

javascript - 将对象函数传递给 d3 中的 data()

javascript - 如何将 svg 转换为 d3.js 代码?

html - Respond.js 隐藏标志图像 ie8

css - IE8 中的圆 Angular 边缘

javascript - 如何获取鼠标当前指向的元素的属性

javascript - 使用 html.innerHTML 设置 html 内容,以便它在 IE 8 和 9 中工作

javascript - 缩放 Raphael/SVG 容器以适应所有内容

javascript - Raphael.js 相当于 JQuerys $(this) 选择器的是什么?

javascript - 如何让clearTimeout()在setTimeout()中发生?