我是 dc.js 的新手。
我有一些数据:
var data =
[
{date: Date.UTC(2015, 4, 4), frame: "frame1" },
{date: Date.UTC(2015, 2, 1), frame: "frame2" },
{date: Date.UTC(2015, 2, 11), frame: "frame3" },
{date: Date.UTC(2015, 1, 4), frame: "frame4" },
];
//create crossfilter
cf = crossfilter(data);
//create dimension
byDate = cf.dimension(function (d) {
return d.date;
});
//create group
byDateGroup = byDate.group();
我正在使用这个 dc.lineChart
:
//configure timeGraph
timeGraph = dc.lineChart("#range")
.width(document.body.clientWidth)
.height(100)
.dimension(byDate)
.group(byDateGroup)
.transitionDuration(500)
.elasticY(true)
.x(d3.time.scale().domain([(byDate.bottom(1))[0].date, (byDate.top(1))[0].date + 1000]))
;
我想访问由可调范围选择器栏过滤的数据。我认为将函数传递给 onfiltered
会起作用,但我不知道要从 chart
访问什么以返回当前过滤的数据。
timeGraph.on("filtered", function (chart) {
console.log(/* print the data filtered by the 'range selector' */);
});
Here's a JSFiddle with an example.如果该示例能够正常运行,那么表中显示的所有内容都应该显示在控制台中。
提前致谢。
最佳答案
在维度上使用top
方法。在您的 fiddle 上下文中,byDate.top(Infinity)
。
https://jsfiddle.net/6p3vhga9/
方法的 Crossfilter API 文档:https://github.com/square/crossfilter/wiki/API-Reference#dimension_top
关于javascript - 从 dc.js 图表访问过滤/剪辑数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30492721/