javascript - 在 div 中移动附加路径 (d3.js)

标签 javascript html css d3.js svg

我有一张 map ,我似乎无法移动它的位置。这是我的 HTML:

<div class="container">
    <!-- Title -->
    <h1 class="title has-text-centered">New York</h1>
    <h2 class="subtitle has-text-centered">Income vs Poverty</h2>

    <div class="columns">
      <div class="column is-half">
        <svg class="current" width="780" height="850" style="text-align:left;" ></svg>
      </div>
       <div class="column is-half">
        <svg class="2015" width="580" height="800"></svg>
      </div>
    </div>

这是我绘制 map 并将其附加到“当前”svg 的地方:

 var geoPath = d3.geoPath()
.projection( albersProjection );



d3.select("svg.current").selectAll("path")
.data( CaliforniaCountiesOverdoses.features )
.enter()
.append( "path" )
.attr( "fill", "white" )
.attr( "opacity", .8 )
.attr( "stroke", "#696969" )
.attr("left", 200)
.attr( "border-radius", '50%' )
.attr( "stroke-width", ".35" )
.attr( "d", geoPath )
    .attr("class","counties")

    .attr("fill", function(d) { 
        var value = currentMap.get(d.properties.ID);
        return (value != 0 ? current_color(value) : "grey");  

问题是我无法移动 map (即 SVG 矩形内的“县”类。我希望它更靠左。我尝试设置“县”的 viewBox ' 类:

$('counties').each(function () { $(this)[0].setAttribute('viewBox', '0 0 100 100') });

并且我尝试了其他 CSS 操作:

.counties {

 text-align: left;

一切都没有运气。任何人都可以告诉我我在这里的方法中缺少什么吗?

最佳答案

did you try... attr('transform','translate(x, y)' where x and y is the number you want to move it? 直接在路径元素上使用它. 这是一个代码笔:

https://codepen.io/anon/pen/aaMPwJ

关于javascript - 在 div 中移动附加路径 (d3.js),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52449993/

相关文章:

javascript - SVG 和 Javascript 在 Chrome 中无法正常工作 'online'

html - CSS3后台查询

javascript - 使用 Restify 我的帖子显示 "converting circular structure to JSON"错误

JavaScript 正则表达式捕获 '%20' 或空格

Jquery 动画在点击时放大/缩小 div(2 次点击)

html - 简单的 HTML CSS 下拉菜单问题

javascript - JQuery UI 添加到 Accordion

javascript - 使用内部有 GIF 的 CSS 移动 div。 GIF 在移动时暂停

javascript - 使用 jQuery 环绕元素组

html - 制作移动友好的html表单