我討厭創建一個新帖子來問這個問題,但由於我還是新手,我無法對帖子發表評論。dc.js/d3.js - 每個類別組的最小/最大值
我基本都爲dc.js - min value from group per day
同樣的問題,但由於的jsfiddle不起來了,我看不出他們是如何解決這個問題。
var data = [
{category: 'A', ..., amount: '13', categoryCount: 1},
{category: 'A', ..., amount: '13', categoryCount: 0},
{category: 'B', ..., amount: '10', categoryCount: 1},
{category: 'A', ..., amount: '3', categoryCount: 1},
{category: 'C', ..., amount: '27', categoryCount: 1},
{category: 'A', ..., amount: '11', categoryCount: 1},
{category: 'B', ..., amount: '18', categoryCount: 2},
{category: 'C', ..., amount: '19', categoryCount: 1},
{category: 'C', ..., amount: ' ', categoryCount: 1},
{category: 'C', ..., amount: '22', categoryCount: 1}
];
我想有一個面積圖包含每個類別的最小值(和最大值)。
我現在有
var bar_graph = dc.barChart("#bar_chart");
var bar_graphDim = ndx.dimension(function(d) {return d.category;});
var bar_graphGroup = bar_graphDim.group().reduceSum(d.categoryCount);
var dateDimGroup = reductio().min(function (d) { return +d.amount; })(bar_graphDim.group());
var dateDimFGroup = remove_empty_bins(dateDimGroup);
bar_graph
.width(150).height(60)
.dimension(bar_graphDim)
.group(dateDimFGroup)
.valueAccessor(function(d) {return d.value.min;}) //added a solution
.renderHorizontalGridLines(true)
.gap(2)
.x(d3.scale.ordinal())
.xUnits(dc.units.ordinal)
.elasticY(true)
.elasticX(true)
.yAxisLabel("counts");
var bar_graphGroupMax = bar_graphDim.group().reduceSum(d.categoryCount);
var dateDimGroupMax = reductio().min(function (d) { return +d.amount; })(bar_graphDim.group());
var dateDimFGroupMax = remove_empty_bins(dateDimGroupMax);
bar_graphMax
.width(150).height(60)
.dimension(bar_graphDim)
.group(dateDimFGroupMax)
.valueAccessor(function(d) {return d.value.max;})
.renderHorizontalGridLines(true)
.gap(2)
.x(d3.scale.ordinal())
.xUnits(dc.units.ordinal)
.elasticY(true)
.elasticX(true)
.yAxisLabel("counts");
你到目前爲止嘗試過什麼?如果你已經有了一個維度和組,那麼鏈接問題中的答案就非常全面。如果你被困在一個較早的步驟,那麼讓我們知道你到目前爲止做了什麼,哪些不起作用,人們會盡力幫助。 –
我試過了: var dateDim = facts.dimension(function(d){return d3.time.day(d.date);}); var dateDimGroup = reductio()。min(function(d){return d.amount;})(dateDim.group()); 但這並沒有做到。我不知道該怎麼辦... – Casey
因此,dateDimGroup.all()不會給你每天的最小值?我希望它能做到這一點。或者你不確定如何將這個變成dc.js圖表? –