- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试删除空容器,或者我应该说 dc.js 数据表中具有 0 值的行。
我已经根据 dc.js 文档常见问题解答中提供的示例和片段编写了我的代码 remove empty bins但我仍然无法达到预期的结果。
我正在尝试使用假组对我的数据进行分组,然后按总数的降序对表格进行排序。
var data = [{salesman: "AB",name: "John",total: 190.1,type: "Tab"},
{salesman: "CD",name: "David",total: 190,type: "Tab"},
{salesman: "EF",name: "Elton",total: 300.5,type: "Visa"},
{salesman: "AB",name: "John",total: 90.0,type: "Tab"},
{salesman: "EF",name: "Elton",total: 90,type: "Tab"},
{salesman: "CD",name: "David",total: 90,type: "Tab"}];
var ndx = crossfilter(data);
var salesManDim = ndx.dimension(function(d) {
return d.salesman;
});
var salesmanSumGroup = salesManDim.group().reduceSum(function(d) {
return (Math.round((d.total) * 100) / 100);
});
var salesmanChart = dc.pieChart("#chart");
salesmanChart
.width(200)
.height(150)
.slicesCap(10)
.innerRadius(30)
.dimension(salesManDim)
.group(salesmanSumGroup);
var salesMan_TypeDim = ndx.dimension(function(d) {
return d.salesman + "/" + d.type;
});
var groupedDimension = salesMan_TypeDim.group().reduce(
function(p, v) {
p.TOTAL += +(Math.round((v.total) * 100) / 100);
p.SALESMAN = v.salesman + " - " + v.name;
p.TYPE = v.type;
return p;
},
function(p, v) {
p.TOTAL -= +(Math.round((v.total) * 100) / 100);
p.SALESMAN = v.salesman + " - " + v.name;;
p.TYPE = v.type;
return p;
},
function() {return { TOTAL: 0, SALESMAN: "",TYPE: ""};});
var rank = function(p) {
return p.key.substr(p.key.lastIndexOf("/") + 1);
};
function remove_empty_bins(source_group) {
function non_zero_pred(d) {
return d.value.TOTAL !== 0;
}
return {
top: function(n) {
return source_group.top(Infinity).filter(non_zero_pred).slice(0, n);
}
};
}
dc.dataTable(".dc-data-table")
.dimension(remove_empty_bins(groupedDimension))
.group(rank)
.size(Infinity)
.columns([
function(d) {
return d.value.SALESMAN;
},
function(d) {
return (Math.round((d.value.TOTAL) * 100) / 100);
}
])
.sortBy(function(d) {
return d.value.TOTAL;
})
.order(d3.descending);
dc.renderAll();
dc.redrawAll();
当我 checkin 调试器时,删除空垃圾箱功能工作正常,但仍然以某种方式未过滤 0 值。是因为我的键的定义方式吗? To best explain my scenario here is a jsFiddle for the above example
最佳答案
它出现在如此简单的示例中令人惊讶,但浮点加法和减法通常会导致值不为零,而您希望它们为零。
这种情况尤其经常发生在十进制数上。 0.1 is unrepresentable in binary floating point numbers, and they are not necessarily associative or distributive.
我们可以添加以下行来诊断问题:
.on('preRedraw', function(chart) {
console.log(chart.dimension().top(Infinity).map(x=>x.value.TOTAL));
})
确实,当我们点击 CD 时,我们会看到:
[200, 370.3, 2.842170943040401e-14]
所以这样写non_zero_pred
:
function non_zero_pred(d) {
return Math.abs(d.value.TOTAL) > 0.0001;
}
零消失了:https://jsfiddle.net/3fovopxp/7/
我现在去解决FAQ...
关于javascript - 无法从 dc.js 数据表中删除空箱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45041136/
我是 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 类的定义中找到了一个构造函
我是一名优秀的程序员,十分优秀!