如何减少凹窝.js中Y轴记号的数量

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

本文关键字:记号 何减少 js      更新时间:2023-09-26

在酒窝.js中,有没有一种方法可以将y轴记号的数量减少一半,这样它只显示每隔一个y记号,而不是所有的y记号?

您可以在绘制后使用一些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/