How to disable the minor ticks in d3 log scale?

吃可爱长大的小学妹 提交于 2020-01-02 18:42:10

问题


I have my real time d3 log scale graph like below:

I would like to show only the major ticks with their labels : 10^-2, 10^-1, 10^0, 10^1, 10^2

but not the minor ticks

I would like to have the log Y axis look like this without the minor ticks:

How can I do this?

EDIT: post some code

svg = d3.select("#chart1").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom);

y = d3.scale.log().domain([1e-1, 1e2]).range([height, 0]);

yAxis = d3.svg.axis().scale(y).orient("left");

svg.selectAll("g.y.axis")
.call(yAxis)    
.selectAll(".tick text")
.text(null)
.filter(powerOfTen)
.text(10)
.append("tspan")
.attr("dy", "-.7em")
.text(function(d) { return Math.round(Math.log(d) / Math.LN10); });

You might also interested to know how to get the custom label of powerOfTen. If so, you might need to refer here

EDIT: You can edit my jsfiddle


回答1:


suggested by Lars Kotthoff

var yAxis = d3.svg.axis().scale(y).tickSize(0).tickValues([1e-1,1e0,1e1,1e2]).orient("left");

this answer force the label, but the major tick is not drawn.....



来源:https://stackoverflow.com/questions/23167075/how-to-disable-the-minor-ticks-in-d3-log-scale

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!