The straight line in D3 is blurry

I am trying to draw a rectangle with a strong dotted line in SVG using D3, but when I make the upper and lower dashed lines, they are blurry. Here is my code:

var width = 400,
        height = 400;

var svg = d3.select('body')
        .append('svg')
            .attr('width', width)
            .attr('height', height)
        .append('g')
            .attr('transform', 'translate('+height/2+','+width/2+')');

svg.append('rect')
    .attr('width', '185')
    .attr('height', '45')
    .attr('x', -height/2+185/2)
    .attr('y', -width/2+10)
    .attr('fill', 'rgba(0,0,0,0)')
    .attr('stroke', '#2378ae')
    .attr('stroke-dasharray', '10,5')
    .attr('stroke-linecap', 'butt')
    .attr('stroke-width', '3')

http://jsfiddle.net/sigscotty/9H9PX/

Here's what it looks like in a browser:

enter image description here

Any way to get top and bottom crunch like sides?

+4
source share
1 answer

shape-rendering is probably what you want. shape-rendering="crispEdges"gotta do it for your business. Alternatively, you can adjust the y and height attributes so that the top and bottom positions are + 0.5.

+6
source

All Articles