【问题标题】:dc.js Scatter Plot and elasticY behaviordc.js 散点图和 elasticY 行为
【发布时间】:2017-12-27 14:55:46
【问题描述】:

是否应该让 ElasticY(true) 在触发重绘事件时让散点图重新计算 y 轴范围?

我已使用 Scatter Brushing 示例进行演示。每个图表都添加了以下属性:

.yAxisPadding('5%')  // Allow the max values to be brushed
.elasticY(true)      // Allow the chart to recalculate the Y axis range

这是一个jsFiddle 示例。

我认为通过刷左散点图,在图表中间选择几个点,会导致右散点图重新计算其 Y 轴范围。但这似乎并不正确。是错误还是我遗漏了什么?

【问题讨论】:

    标签: javascript d3.js dc.js crossfilter


    【解决方案1】:

    elasticXelasticY 一样,dc.js 会查看所有垃圾箱,无论它们是否为空。

    您可能会争辩说它忠实地显示了所有数据,只是碰巧其中一些数据为零。 :-)

    要删除这些零,请使用常见问题解答中的remove_empty_bins

        function remove_empty_bins(source_group) {
            return {
                all: function () {
                    return source_group.all().filter(function(d) {
                        //return Math.abs(d.value) > 0.00001; // if using floating-point numbers
                        return d.value !== 0; // if integers only
                    });
                }
            };
        }
        chart1
            .group(remove_empty_bins(group1))
        chart2
            .group(remove_empty_bins(group2))
    

    Fork of your fiddle.

    请注意,散点图joins the data in a naive way 没有提供非常好的动画过渡。我通常建议使用 .transitionDuration(0) 关闭散点图的转换,因为它们没有用。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-23
    • 2019-05-08
    • 1970-01-01
    • 2015-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多