Question

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

my real time log scale graph

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:

enter image description here

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

Was it helpful?

Solution

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.....

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top