cla*_*era 6 javascript d3.js crossfilter dc.js
我是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();
Run Code Online (Sandbox Code Playgroud)
我正在使用这个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]))
;
Run Code Online (Sandbox Code Playgroud)
我想访问由可调范围选择器栏过滤的数据.我认为传递一个函数onfiltered
可以工作,但我不知道要从哪里访问chart
以返回当前过滤的数据.
timeGraph.on("filtered", function (chart) {
console.log(/* print the data filtered by the 'range selector' */);
});
Run Code Online (Sandbox Code Playgroud)
这是一个带有示例的JSFiddle.如果示例正常工作,表中显示的所有内容都应显示在控制台中.
提前致谢.
top
在维度上使用该方法.在你的小提琴的背景下,byDate.top(Infinity)
.
https://jsfiddle.net/6p3vhga9/
该方法的Crossfilter API文档:https://github.com/square/crossfilter/wiki/API-Reference#dimension_top
归档时间: |
|
查看次数: |
1899 次 |
最近记录: |