![](/img/trans.png)
[英]D3.js Focus+Context via Brushing Barchart - Recalculate BarWidth on Brushing
[英]D3.js Focus+Context via Brushing Ordinal Scale
我對d3.js仍然很陌生,並已通過“刷塗”向我的散點圖中添加了“焦點+上下文”,該散點圖具有對數y軸和序數x軸比例,但無法正常工作。 筆刷似乎在X軸上偏移了一些,但不僅顯示了選定的項目。
下面是我的刷機功能:
// Brush Function
function brushed() {
var extent = brush.extent();
var d = xScale2.domain(),
r = xScale2.range();
extent = extent.map(function(e) { return d[d3.bisect(r, e) - 1]; });
xScale.domain(brush.empty() ? d : extent);
focus.select(".x.axis")
.call(xAxis)
.selectAll("text")
.style("text-anchor", "end")
.attr("dx", "-.8em")
.attr("dy", ".15em")
.attr("transform", "rotate (-65)");
focus.selectAll(".point")
.attr("d", d3.svg.symbol().type(function(d) { return symbols[d.TYPE_CODE]; }))
.attr("transform", function(d) { return "translate(" + xScale(dateFn(d)) + "," + yScale(d.TYPE_VALUE) + ")"; })
.style("fill", function(d) { return colors[d.TYPE_CODE]; });
}
如果有人可以提供幫助(尤其是我必須更改的所有地方以及更改方式),我將很樂意讓它正常工作並了解我在做錯什么。
完整代碼位於: http : //jsfiddle.net/brebuck/LL42b4L7/
想出了我自己的解決方案。
將畫筆功能更改為:
// Brush Function
function brushed() {
var extent = brush.extent();
var d = xScale2.domain();
// Find out what is selected between the extent on the Ordinal Axis.
var SymbolInside = data.filter(function(d) {
return extent[0] <= xScale2(dateFn(d)) && xScale2(dateFn(d)) <= extent[1];
});
// Convert the Array of objects to return a single array of dates used for the ordinal axis.
SymbolInside = SymbolInside.map(function (d) { return dateFn(d); });
xScale.domain(brush.empty() ? d : SymbolInside);
focus.select(".x.axis")
.call(xAxis)
.selectAll("text")
.style("text-anchor", "end")
.attr("dx", "-.8em")
.attr("dy", ".15em")
.attr("transform", "rotate (-65)");
focus.selectAll(".point")
.attr("d", d3.svg.symbol().type(function(d) { return symbols[d.TYPE_CODE]; }))
.attr("transform", function(d) { return "translate(" + xScale(dateFn(d)) + "," + yScale(d.TYPE_VALUE) + ")"; })
.style("fill", function(d) { return colors[d.TYPE_CODE]; });
}
更新的代碼位於: http : //jsfiddle.net/brebuck/LL42b4L7/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.