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

标签 javascript dimple.js

在 dimple.js 中有没有办法,例如,将 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;
            });
        }
    }
};

这是 fiddle :

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

关于javascript - 如何减少 dimple.js 中 Y 轴刻度的数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23305230/

相关文章:

javascript - 在dimplejs 中显示之前操作数据

javascript - 如何更改dimple.js中工具提示的位置和大小

Javascript 在一个 HTML 页面内的页面之间旋转

javascript - 在变量中获取电子邮件,然后推送 onclick 事件

javascript - 表示 2 个或更多 dimple.js 图表

r - 如何使用 rCharts、dPlot 和 dimple 更改轴标题

javascript - dimple.js 中的 eventArgs 显得不完整

javascript - 弹出窗口打开后立即变灰并禁用父窗口

javascript - 文本区域内的 HTML5 富文本

javascript - 如何在 JavaScript 中替换特定索引处的字符?