Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you reduce the number of Y-axis ticks in dimple.js?

In dimple.js is there a way to, for example, reduce the number of y-axis ticks by half so that it would only show every other y tick instead of all of them?

like image 493
cmgerber Avatar asked Apr 26 '14 00:04

cmgerber


1 Answers

You can modify it after draw with some d3. Here is a method which will remove the labels leaving every nth one:

// Pass in an axis object and an interval.
var cleanAxis = function (axis, oneInEvery) {
    // This should have been called after draw, otherwise do nothing
    if (axis.shapes.length > 0) {
        // Leave the first label
        var del = 0;
        // If there is an interval set
        if (oneInEvery > 1) {
            // Operate on all the axis text
            axis.shapes.selectAll("text").each(function (d) {
                // Remove all but the nth label
                if (del % oneInEvery !== 0) {
                    this.remove();
                    // Find the corresponding tick line and remove
                    axis.shapes.selectAll("line").each(function (d2) {
                        if (d === d2) {
                            this.remove();
                        }
                    });
                }
            del += 1;
            });
        }
    }
};

Here's the fiddle:

http://jsfiddle.net/V3jt5/1/

like image 183
John Kiernander Avatar answered Oct 03 '22 05:10

John Kiernander