你如何减少dimple.js中Y轴刻度的数量?

时间:2014-04-26 00:45:51

标签: javascript dimple.js

在dimple.js中有一种方法,例如,将y轴刻度的数量减少一半,以便它只显示每个其他y刻度而不是所有它们?

1 个答案:

答案 0 :(得分:6)

你可以用d3绘制后修改它。这是一种方法,它将删除每个第n个标签:

// 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;
            });
        }
    }
};

这是小提琴:

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