D3 ticks() does not return value if provided scale has only 1 result

前端 未结 3 1819
借酒劲吻你
借酒劲吻你 2021-01-28 03:35

I have an x-axis that displays the days that my data occurs on. The data is dynamic and sometimes I have data for only 1 day, 2 days, n days, etc.

Here is my code for di

3条回答
  •  耶瑟儿~
    2021-01-28 03:55

    .ticks() should be used to set the number of ticks you'd like to have on your axis, not the kind of data that should be in them. So try to set it like .ticks(3) and it should set a couple of ticks.
    From the wiki:
    .ticks([count])
    Returns approximately count representative values from the scale's input domain. If count is not specified, it defaults to 10. The returned tick values are uniformly spaced, have human-readable values (such as multiples of powers of 10), and are guaranteed to be within the extent of the input domain. Ticks are often used to display reference lines, or tick marks, in conjunction with the visualized data. The specified count is only a hint; the scale may return more or fewer values depending on the input domain.

提交回复
热议问题