【问题标题】:crossfilter dimension not rendering the counts交叉过滤器维度不呈现计数
【发布时间】:2019-07-18 15:27:38
【问题描述】:

我有一组数据,我想在折线图上呈现频率

数据解析

var volumeChart = dc.barChart('#monthly-volume-chart');

var dateFormatSpecifier = '%Y-%m-%dT%H:%M:%S.000Z';
    var dateFormat = d3.timeFormat(dateFormatSpecifier);
    var dateFormatParser = d3.timeParse(dateFormatSpecifier);
    var numberFormat = d3.format('.2f');

    data.forEach(function (d) {
        d.dd = dateFormatParser(d.timestamp);
        d.minute = d3.timeMinute(d.dd)
        //coerce to number with a +
    });

维度分组

var freqByMins = ndx.dimension(function (d) {
    return d.minute;
});
var aa = freqByMins.group()
console.log(aa.all())
var freqByMinsGroup = aa.reduceCount(function (d) {
    return d.minute;
});
console.log(freqByMinsGroup.all())

查看freqByMinsGroup.all()我得到以下数据

0: {key: Thu Feb 21 2019 05:29:00 GMT+0800 (Singapore Standard Time), value: 2}
1: {key: Thu Feb 21 2019 05:30:00 GMT+0800 (Singapore Standard Time), value: 5}
2: {key: Thu Feb 21 2019 05:31:00 GMT+0800 (Singapore Standard Time), value: 6}
3: {key: Thu Feb 21 2019 05:32:00 GMT+0800 (Singapore Standard Time), value: 3}
4: {key: Thu Feb 21 2019 05:33:00 GMT+0800 (Singapore Standard Time), value: 1}
5: {key: Thu Feb 21 2019 05:34:00 GMT+0800 (Singapore Standard Time), value: 1}
6: {key: Thu Feb 21 2019 05:35:00 GMT+0800 (Singapore Standard Time), value: 3}
7: {key: Thu Feb 21 2019 05:36:00 GMT+0800 (Singapore Standard Time), value: 4}
8: {key: Thu Feb 21 2019 05:38:00 GMT+0800 (Singapore Standard Time), value: 4}
9: {key: Thu Feb 21 2019 05:39:00 GMT+0800 (Singapore Standard Time), value: 7}
length: 10

渲染图表

 volumeChart.width(960)
    .height(100)
    .margins({top: 10, right: 10, bottom: 20, left: 40})
    .dimension(freqByMins)
    .group(freqByMinsGroup)
    .transitionDuration(500)
    .elasticY(true)

    .x(d3.scaleTime().domain([new Date(2019, 2, 21, 5, 29, 0), new Date(2019, 2, 21, 5, 40, 0)]))
    .xAxis();

但是,我的交叉过滤器图表没有呈现任何计数。

附上一张图片

【问题讨论】:

    标签: d3.js dc.js crossfilter


    【解决方案1】:

    如果没有运行示例很难说,因为这看起来基本没问题

    但请尝试:

    .xUnits(d3.timeMinutes) // to tell the chart how many entries
    .x(d3.scaleTime()) // let the chart calculate the domain
    .elasticX(true)
    

    例如,如果您自己不在新加坡时区,您可能会遇到麻烦。除非您需要额外的控制,否则使用 elasticX/elasticY 总是更容易。

    我用你的聚合数据建立了一个dummy fiddle 和一个假组,它起作用了。

    【讨论】:

    • 只想感谢您的快速回复。非常感谢我的两个问题
    • 没问题!很高兴能提供帮助。
    • 只是为了检查。当我运行交叉过滤器时,ElasticX 似乎忽略了数据的最右端。而且它似乎没有生成 y 轴。我使用了条形图,所以我希望至少有一个项目的频率计数,因为我使用了 reduceCount
    • 嗯,是的,它太字面意思了。顶点是域的末端,这对于条形图来说是有问题的(但对于折线图来说还可以)。 Workaround here.
    • 不知道你说的不生成 Y 轴是什么意思,对我来说听起来并不熟悉。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-28
    • 2016-01-11
    • 2023-03-03
    • 1970-01-01
    相关资源
    最近更新 更多