d3.js - controlling ticks and bins on a histogram

前端 未结 1 425
名媛妹妹
名媛妹妹 2021-02-06 12:40

I\'m trying to build a histogram script that compares values within, say, 20% of some \"focus\" value.

So, for a focus value of 75, I\'d look at values ranging from 60 t

相关标签:
1条回答
  • 2021-02-06 13:11

    From the documentation on .ticks():

    The specified count is only a hint; the scale may return more or fewer values depending on the input domain.

    Instead of messing around with .ticks(), just make the bins yourself:

    tempScale = d3.scale.linear().domain([0, bins]).range([lowerBand, upperBand]);
    tickArray = d3.range(bins + 1).map(tempScale);
    

    and pass that array to .tickValues() and .bins().

    0 讨论(0)
提交回复
热议问题