d3 / d3-axis

Human-readable reference marks for scales.

Home Page:https://d3js.org/d3-axis

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not easy to have integer scale

adamborowski opened this issue · comments

I have a chart with linear scale axis.
Now if I want to have integers only on axis, I have to override scale.ticks() method which isn't an elegant way to do that:

    const _ticks = y.ticks;
    y.ticks = (...args) => {
        const ticks = _ticks.apply(y, args);
        return ticks.filter(a => Math.floor(a) === a);
    };

Any ideas how to improve tick generation customization?
Maybe ticks generator function as an option of axis, then having built-in multiple ticks generator functions?

Use axis.tickValues.

Please use Stack Overflow tag d3.js to ask for help. Although I make an effort to assist everyone that asks, I am not always available to provide help promptly or directly. Stack Overflow provides a better collaborative forum for self-help: tens of thousands of D3-related questions have already been asked there, and some answered questions may be relevant to you.

When asking for help, please include a link to a live example that demonstrates the issue, preferably on bl.ocks.org. It is often impossible to debug from code snippets alone. Isolate the issue and reduce your code as much as possible before asking for help. The less code you post, the easier it is for someone to debug, and the more likely you are to get a helpful response.

If you have a question about D3’s behavior and want to discuss it with other users, also consider the d3-js Google Group or joining the d3-js Slack.

Thank you! 🤗