简体   繁体   English

D3图表的Y轴线在某些分辨率下不可见

[英]D3 chart Y axis line is not visible in some resolutions

I have a stacked bar chart similar to this link , graph is plotted correctly but the problem is y axis line is invisible. 我有一个类似于此链接的堆积条形图,图形已正确绘制,但问题是y轴线不可见。 But if you increase the browser page size in the example chart, you can see like at some resolution x, y axis lines and horizontal tick lines will appear. 但是,如果您在示例图表中增加浏览器页面大小,则可以看到以某种分辨率出现的x,y轴线和水平刻度线。 So x, y axis lines and horizontal tick lines are appearing and disappearing subjected to resolution of the page. 因此,x,y轴线和水平刻度线的出现和消失取决于页面的分辨率。 How to solve this? 如何解决呢?

I am defining x and y axis like below 我正在定义x和y轴,如下所示

var yAxis = d3.svg.axis()
  .scale(y)
  .orient("left")
  .ticks(5)
 .tickSize(-width - 180, 0, 0)
  .tickFormat(d3.format("$"));

var xAxis = d3.svg.axis()
  .scale(x)
  .orient("bottom")
  .tickFormat(d3.time.format("%b"));

svg.append("g")
  .attr("class", "y axis")
  .attr("transform", "translate(0,0)")
  .call(yAxis);

svg.selectAll('.axis line, .axis path')
.style({ 'stroke': '#ddd', 'fill': 'none', 'stroke-width': '1px' });


svg.append("g")
  .attr("class", "x axis")
  .attr("transform", "translate(0," + height + ")")
  .call(xAxis);

Problem was solved after setting 设置后问题解决

shape-rendering: geometricPrecision;

in the place of 代替

shape-rendering: crispEdges;

I hope it helps somebody in future. 希望以后对您有所帮助。

It might be helpful to see it in action but its possible that you are drawing the axis at the end of the svg. 实际使用它可能会有所帮助,但是可能会在svg的末端绘制轴。 You could try adding the style "overflow: visible" to the svg element to make sure that there is enough space to show your axis. 您可以尝试向svg元素添加样式“ overflow:visible”,以确保有足够的空间来显示轴。 If thats the problem you need to position your axis away from the edges. 如果那是问题,则需要将轴放置在远离边缘的位置。

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

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