简体   繁体   English

D3.js为什么某些矩形的笔触比其他矩形宽(在堆积的条形图中)?

[英]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. 我已经开发了一个Marimekko图表,该图表还可以,除了一些矩形周围的线看起来是2px,而其余的是1px。 What can cause this? 是什么原因造成的?

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

I recall having this problem initially with D3. 我记得D3最初有这个问题。 You have to shift the offending elements by 0.5 pixels to the left or right. 您必须将有问题的元素向左或向右移动0.5个像素。 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: 将下面的代码添加到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. 出于相同的原因,我将此代码用于所有包含svg矩形的图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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