- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 jsfiddle 上有以下示例:https://jsfiddle.net/woolycew65/bp5eavxy/并且很好奇我是否可以选择饼图切片 TP-0 和 TP-2 来表示找到同时具有时间点 0 和时间点 2 而不是 0 或 2 的患者。
数据集示例如下所示:
let data = [
{patientId: 101, site: "AAA", timepoints: [0, 2, 4, 6, 8, 12, 18, 24]},
{patientId: 102, site: "AAA", timepoints: [0, 2, 4, 6]},
{patientId: 103, site: "AAA", timepoints: [8, 12, 18, 24]},
{patientId: 104, site: "AAA", timepoints: [0, 4, 8, 18]},
{patientId: 105, site: "AAA", timepoints: [2, 6, 12, 24]},
{patientId: 501, site: "BBB", timepoints: [0]},
{patientId: 502, site: "BBB", timepoints: [2]},
{patientId: 503, site: "BBB", timepoints: [4]},
{patientId: 504, site: "BBB", timepoints: [6]},
{patientId: 505, site: "BBB", timepoints: [8]},
{patientId: 506, site: "BBB", timepoints: [12]},
{patientId: 507, site: "BBB", timepoints: [18]},
{patientId: 508, site: "BBB", timepoints: [24]}
];
我希望生成的交集过滤器生成“AAA”(2)、“BBB”(0),因为 AAA 站点(101 和 102)有两名患者的时间点为 0 AND 2 并且 BBB 现场没有符合交叉点过滤条件的患者。
显然,结果数据集返回“AAA”(4)、“BBB”(2),因为 AAA 站点(101、102、104 和 105)有四名患者的时间点为 0 OR BB 站点的 2 名和两名患者符合联合过滤标准。
如果无法通过交叉过滤器实现,那么我假设我需要在 tpPie 图表上捕获一些事件并执行我自己的过滤,然后用新数据重新填充交叉过滤器。
如有任何帮助,我们将不胜感激。
最佳答案
感谢@EthanJewett 的评论和上述评论中的 crossfilter 示例。我断断续续地搜索了好几个月,最后决定专心致志地寻找答案。 @Gordon 你可能也对这个例子感兴趣。
我已经能够将最终的 dc.js 和交叉过滤器放在一起 example您可以在其中选择根据交集(和)或并集(或)过滤时间点。
如果您选择 TP-6 和 TP-8 并在 or/and 之间切换,您会看到它起作用了。 and 选项表示我正在寻找时间点为 6 和 8 的患者。
我在数据集中添加了一个附加字段“性别”和另一个站点“CCC”。
根据 Ethan 的指导,我缺少的关键部分是定义一个附加维度,当时间点饼图开始作为交集(和)过滤时将被过滤。
时间点饼图维度定义如下。 true 参数让维度知道数据是一个数组:
let tpDimension = ndx.dimension(function (d) {return d.timepoints;}, true);
额外的维度也像上面定义的那样,只是我们没有分解数组,因此没有传递真正的参数。该维度仅在时间点饼图filterHandler中使用。
let tp2Dimension = ndx.dimension(function (d) {return d.timepoints;});
如果用户选择了和选项,时间点饼图过滤器处理程序将被覆盖以使用额外维度。
tpPie.filterHandler(function (dimension, filters) {
if (filters.length === 0) {
// the empty case (no filtering)
dimension.filter(null);
} else if (filters.length === 1 && !filters[0].isFiltered) {
// single value and not a function-based filter
dimension.filterExact(filters[0]);
} else if (filters.length === 1 && filters[0].filterType === 'RangedFilter') {
// single range-based filter
dimension.filterRange(filters[0]);
} else {
// an array of values, or an array of filter objects
dimension.filterFunction(function (d) {
for (var i = 0; i < filters.length; i++) {
var filter = filters[i];
if (filter.isFiltered && filter.isFiltered(d)) {
return true;
} else if (filter <= d && filter >= d) {
return true;
}
}
return false;
});
};
// -------------------------------------------------------------
// Custom code to handle intersection filtering (AND)
if (glbTpFilterOption === 'tpAND') {
tpIntersectFilter(filters);
}
return filters;
});
执行时间点交叉过滤的实际代码是:
function tpIntersectFilter(filters) {
if (filters.length === 1) {
// Do not perform the intersect test when only 1 filter selected
tp2Dimension.filterAll();
} else if (filters.length === 0) {
// Since nothing is filtered we need to perform an intersect
// based on all keys.
tp2Dimension.filter(function (d) {
uniqueObjs = tpGroup.all();
for (var i = 0; i < uniqueObjs.length; i++) {
if (d.indexOf(uniqueObjs[i].key) == -1) return false;
}
return true;
});
} else {
tp2Dimension.filter(function (d) {
// Since we are looking for the intersection, test all
// filters, but once there isn't a match get out.
for (var i = 0; i < filters.length; i++) {
if (d.indexOf(filters[i]) == -1) return false;
}
return true;
});
}
}
最后,当用户在选项之间切换时,我需要处理:
$('#tpFilterOptions a').on('click', function () {
var sel = $(this).data('title');
var tog = $(this).data('toggle');
$('#' + tog).prop('value', sel);
$('a[data-toggle="' + tog + '"]').not('[data-title="' + sel + '"]').removeClass('active').addClass('notActive');
$('a[data-toggle="' + tog + '"][data-title="' + sel + '"]').removeClass('notActive').addClass('active');
glbTpFilterOption = sel;
if (sel === "tpOR") {
tp2Dimension.filterAll();
} else {
tpIntersectFilter(tpPie.filters());
}
dc.redrawAll();
})
关于dc.js - 我可以根据 crossfilter/dc.js 中的交集(和)过滤数据吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45487174/
我是 dc.js 的新手,我对 dc 的灵 active 有一些疑问。 首先,我一直在寻找答案,但还没有找到任何答案。 1) 我正在使用 dc.sunburst 图表。我想知道是否有可能创建 Zoom
谁能解释一下 ldap 字符串部分的构成。 我有一个是: string strSQL = "SELECT mail FROM 'LDAP://DC=amrs,DC=win,DC=ml,dc=COM'
他们已经就如何将 dc.js 简单地用作图形库(例如绘制饼图、条形图...)而不需要交叉过滤器进行了各种讨论,例如,如果您只想在数据已经是一个(标签,值)。 我没有找到任何关于如何做到这一点的例子。这
当我点击数据表中的一行时,我需要过滤其他图表。 我做了 my_table.on('pretransition', function (table) { table.selectAll('td
我想显示小切片( chart.minAngleForLabel(0.05) )的标签,避免文本重叠。 我添加了一个将标签移向外边缘的renderlet: .on('renderlet', func
如何在新列的 dc.js 数据表中添加带有事件监听器的按钮。 如果可能的话,我基本上想添加自定义 html。 最佳答案 添加按钮只是返回列的 html 的问题 dc.dataTable (dom) .
这个问题在这里已经有了答案: Initial Range selection in DC.js chart (1 个回答) 关闭 7 年前。 我创建了 this可视化,并希望在解释文本中使用预定义的
我用 dc.js 制作了一个热图,我想知道 dc.js 中是否有热图的键或图例函数。我在互联网上搜索过,但似乎找不到内置的方法,那么有没有其他人解决过这个问题? 最佳答案 我遇到了同样的任务,我所做的
我有一个具有以下模型的数据源: [ { days : 3, value : 500 }, { days : 30,
如果过滤后 dc.js 中的行图值为零,我们如何隐藏。我们有这样的代码: var kurum=data.dimension(function(d){return ""+ d.KURUM;});
自 1.4.0-alpha.06 版起,Crossfilter 支持数组维度 https://github.com/crossfilter/crossfilter/wiki/API-Reference
我希望在 dc.js 的多维数据集中绘制与连续变量关联的几个直方图。虽然使用 dc.barChart 组件很容易实现这一点,但我希望对这些直方图进行面积归一化。在我的例子中,bin 宽度是统一的,所以
我目前正在尝试弄清楚如何使用 DJ.js 和 D3.js 计算要显示的唯一记录数 数据集如下所示: id,name,artists,genre,danceability,energy,key,loud
在此图表上:http://junklogic.com/dcjs/barpie/index-controls.html 我的示例 JSON 文件中有与严重性评级相对应的图例,该文件代表我将在生产中使用的
我有以下数据。 我可以使用 dc.js 创建一个吗? 有人可以帮助我使用 dc js 创建直方图吗? 搜索了整个论坛但除了这个post 找不到有用的东西. 日期: numbers11012035242
以下是一组数据: var data = [{ machine1: [ {x:"20/12/2014", y:2}, {x:"21/12/2014", y:10} ]},{ machine2:
我使用 dc.js 和 crossfilter 创建了一个折线图。当前图表如下所示: 必需:我希望左上角的事件非事件图例位于中心图表的下方(底部),并且 x 轴刻度标签应该从一月到十二月开始。我在下面
我仍在尝试使用 dc 和 crossfilter 将图表链接在一起,这里我将表格和饼图链接在一起。链接在图表和表格之间起作用,因此当我单击饼图时,表格会相应更新。 然而,当我点击超链接时,这一行似乎没
我对允许打印填充填充对象的修复有疑问... 所以,完整的故事是我们使用了 Windows GDI FloodFill 函数,我们注意到它在打印机上不起作用,所以我在 inet 上找到的是创建一个内存
我是 MFC 编程的新手。这些天我正在使用 Jeff Prosise 的书来学习 MFC 编程。我遇到过:CClientDC dc (this); 我从 CClientDC 类的定义中找到了一个构造函
我是一名优秀的程序员,十分优秀!