我正在尝试从具有16个值(并非全部都是数字)的对象的单个交叉过滤器维度中创建一个包含4个框的框图。我希望这些值来自A,C,C2和G。出于某种原因,我收到一条错误消息,说data.map.sort不是一个函数:
示例对象:
A: 6.666666666666665
AN: 18
C: 9.999999999999998
CN: 28
C2: 10
C2N: 21
G: 2.0000000000000013
GN: 19
N/A: NaN
analyze_url: "some string"
collection_mode: "default"
collector_id: "some irrelevant number"
custom_value: ""
custom_variables: {}
date_created: "2019-09-15T12:06:47+00:00"
date_modified: "2019-09-15T12:16:50+00:00"
创建箱形图:
dimension = createDimension(ndx);
let columns = ['G', 'C', 'C2', 'A']
function createBoxPlot() {
const boxPlot = new dc.BoxPlot(divRef);
let group = dimension.group().reduce(
function reduceAdd(p, v) {
columns.forEach(function(c) {
// keep array sorted for efficiency
p[c].splice(d3.bisectLeft(p[c], v[c]), 0, v[c] || 0);
});
return p || 0;
},
function reduceRemove(p, v) {
columns.forEach(function(c) {
p[c].splice(d3.bisectLeft(p[c], v[c]), 1);
});
return p || 0;
},
function reduceInitial() {
let p = {};
columns.forEach(function(c) {
p[c] = [];
});
return p || 0;
});
boxPlot
.dimension(dimension)
.margins({top: 10, right: 50, bottom: 30, left: 50})
.group(group)
.valueAccessor(function (p) {
console.log(p);
return p || 0;
})
// .elasticY(true)
// .elasticX(true)
.width(700)
.height(500);
return boxPlot;
}
return createBoxPlot();
}
我收到以下错误:
TypeError: data.map(...).sort is not a function
SVGGElement.<anonymous>
node_modules/dc/dist/dc.js:4674
4671 | // For each small multiple…
4672 | function box (g) {
4673 | g.each(function (data, index) {
> 4674 | data = data.map(value).sort(d3Array.ascending);
4675 | const _g = d3Selection.select(this);
4676 | const n = data.length;
4677 | let min;