1

I get this error: "svg.append(...).attr(...).attr(...).call(...).tickFormat is not a function

var x = d3.scaleLinear().domain([0, data.length]).range([0, width]);
var y = d3.scaleLinear().domain([-1, 1]).range([height, 5]);
// Add the X Axis
svg.append("g")
    .attr("class", "x axis")
    .attr("transform", "translate(0," + y(0) + ")")
    .call(d3.axisBottom(x))
    .ticks(20)
    .tickFormat(d3.format(".0s"))

I want to put all the value of x axis to integer.

diralik
  • 6,391
  • 3
  • 28
  • 52
  • 1
    Put the `.ticks()` and `.tickFormat` right after the `d3.axisBottom(x)` . Like this `d3.axisBottom(x).ticks().tickFormat()` etc – Robert Andersson Dec 11 '18 at 10:10
  • Thanks it works! But the value comes out like [0,0.5,1,1.5,2,2.5 ...]. Is there any way that I can put it to [0,1,2,3,4,5]? –  Dec 11 '18 at 10:50
  • 1
    I'm not sure where you're getting those values from or why, what type of chart you're trying to create etc so it's difficult to help with that small snippet of code, post a new question with more context and you'll get help. – Robert Andersson Dec 11 '18 at 11:16
  • @user10278838 See [this answer](https://stackoverflow.com/a/56821215/5812238) – diralik Jun 29 '19 at 22:28

0 Answers0