最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - D3 chart Y axis line is not visible in some resolutions - Stack Overflow

programmeradmin2浏览0评论

I have a stacked bar chart similar to this link, graph is plotted correctly but the problem is y axis line is invisible. 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. So x, y axis lines and horizontal tick lines are appearing and disappearing subjected to resolution of the page. How to solve this?

I am defining x and y axis like below

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);

I have a stacked bar chart similar to this link, graph is plotted correctly but the problem is y axis line is invisible. 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. So x, y axis lines and horizontal tick lines are appearing and disappearing subjected to resolution of the page. How to solve this?

I am defining x and y axis like below

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);
Share Improve this question asked Jul 2, 2015 at 7:19 Nagendra SomayajiNagendra Somayaji 1812 silver badges17 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

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. You could try adding the style "overflow: visible" to the svg element to make sure that there is enough space to show your axis. If thats the problem you need to position your axis away from the edges.

发布评论

评论列表(0)

  1. 暂无评论