Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create d3.js axes without numbering

Is there a way to create a d3.js axis without any kind of numbering? Tickmarks are ok but just no numbers at all. Currently I'm creating my d3.js axis with the code below. Thanks in advance.

 // create Axis
  svg.selectAll("axis")
      .data(d3.range(angle.domain()[1]))
    .enter().append("g")
      .attr("class", "axis")
      .attr("transform", function(d) { return "rotate(" + angle(d) * 180 / Math.PI + ")"; })
    .call(d3.svg.axis()
      .scale(radius.copy().range([0,0]))
      .ticks(1)
      .orient("left"))
    .append("text")
    .style("color", "white") 
      .attr("y", 
        function (d) {
          if (window.innerWidth < 455){
            console.log("innerWidth less than 455: ",window.innerWidth);
            return -(0);
          }
          else{
            console.log("innerWidth greater than 455: ",window.innerWidth);
            return -(0);
          }
        })
      .attr("dy", "0em");
like image 304
Apollo Avatar asked Jul 27 '12 16:07

Apollo


1 Answers

The simplest way to hide tick labels is via CSS:

.axis text { display: none; }

Alternatively, you could use the empty string as the tick format:

axis.tickFormat("");

Or, you could use post-selection to remove the text elements after creating the axis:

selection.call(axis).selectAll("text").remove();

Of course, I prefer CSS as it's the most declarative. Example here:

  • http://bl.ocks.org/3048740
like image 160
mbostock Avatar answered Oct 14 '22 10:10

mbostock