简体   繁体   中英

D3.js Why do some rectangles have wider strokes than others (in a stacked bar chart)?

I've developed a Marimekko chart which is OK except that the lines around some rectangles appear to be 2px, whereas the rest are 1px. What can cause this?

矩形的宽度或位置存在一个舍入问题。

I recall having this problem initially with D3. You have to shift the offending elements by 0.5 pixels to the left or right. That cleared up the problem for me. I read an article that pointed out the necessity of the approach, I just don't remember where.

Add the code below somewhere in your css:

svg {
  shape-rendering: crispEdges;
}

Most likely you will not have the problem you described anymore. I can't guarantee it, but chances are good. I use this code for all diagrams containing svg rectangles, and for the same reason.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM