如何减少dimple.js中的Y轴刻度数? [英] How do you reduce the number of Y-axis ticks in dimple.js?

查看:60
本文介绍了如何减少dimple.js中的Y轴刻度数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,在dimple.js中,有一种方法可以将y轴刻度线的数量减少一半,以便仅显示所有其他y刻度线,而不是所有的y刻度线.

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?

推荐答案

使用d3绘制后可以对其进行修改.这是一种方法,该方法将删除每第n个留下的标签:

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

这是小提琴:

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

这篇关于如何减少dimple.js中的Y轴刻度数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆