dc.js和crossfilter - 根本不读json

时间:2018-01-12 05:43:11

标签: javascript dc.js crossfilter

我有尝试导入geojson的问题(这似乎有效)但是然后将其传递给crossfilter - 似乎没有数据加载到crossfilter对象中。

我在这里做了一个jsfiddle:https://jsfiddle.net/Svarto/pLyhg9Lb/

当我尝试console.log(ndx),即crossfilter时,我只获得没有加载的crossfilter对象(当我尝试console.log任何类型的组时都一样:

enter image description here

在将带有加载数据的交叉过滤器写入控制台时,我本来期望某种数据。当我尝试用数据绘制直方图时问题变得明显 - 只有2个不符合我的预期。

代码是这样的:

d3.json("https://dl.dropboxusercontent.com/s/7417jc3ld25i0a4/srealitky_geojson.json?dl=1", function(err,json){

var h = 300;
            var w = 350;

            var ndx = crossfilter();
            console.log(json.features);
            ndx.add(json.features);
            console.log(ndx);

            var all = ndx.groupAll();


            var yieldDimension = ndx.dimension(function(d){
                return d.properties.yields
            });


            var yieldGroup = yieldDimension.group().reduceCount();
            console.log(yieldGroup);

            var priceDimension = ndx.dimension(function(d){
                return d.properties.price
            });

            var priceGroup = priceDimension.group().reduceCount();

            var barChart = dc.barChart("#yieldChart");

            barChart.width(350)
            .height(300)
            .x(d3.scale.linear().domain([0,30]))
            .brushOn(false)
            .dimension(yieldDimension)
            .group(yieldGroup);

            dc.renderAll();

  }

1 个答案:

答案 0 :(得分:1)

正如@Nilo上面所指出的那样,问题不在于读取json数据,而是设置坐标。

您可能希望通过舍入到精确度0.01:

来合并数据
#

然后清理边距,添加 var yieldGroup = yieldDimension.group(function(yields) { return Math.floor(yields*100)/100; }).reduceCount(); elasticX,并指定要匹配的elasticY,我们得到一个漂亮的直方图(具有正态分布):

xUnits

with 0.01 precision

Fork of your fiddle.

with 0.001 precision

With 0.001 precision.

有关详细信息,请参阅the documentation for coordinateGridMixin

相关问题