Why are some of the grid lines randomly disappearing on my responsive D3 chart?

戏子无情 提交于 2019-12-01 07:40:09
altocumulus

That is an aliasing effect which will occur because the way the lines will get rendered is influenced by various factors. The main three of them being stroke width, position and rendering mode. For using shape-rendering: crispEdges the SVG spec states:

To achieve crisp edges, the user agent might turn off anti-aliasing for all lines...

Depending on the scaling and the translation of the line it may be calculated to appear between two screen pixels while the scaled stroke width is not broad enough to color any of those adjacent screen pixels. That way the lines seem to randomly disappear and appear again.

Further explanations can be found in "Why is SVG stroke-width : 1 making lines transparent?" or in my answer to "Drew a straight line, but it is crooked d3".

For your code you can change the rendering behaviour by using shape-rendering: geometricPrecision instead of crispEdges when drawing the grid lines. Have a look at the updated JSFiddle for a working example.

In my case I simply solved this issue by setting "showMaxMin" to false.

    lineChart.xAxis.showMaxMin(false).tickValues(xAxisTickValues).tickFormat(function (d) {
    if (typeof d === 'string') {
        d = parseFloat(d);
    }
    return d3.time.format("%d %b")(new Date(d));
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!