[英]to resize the existing lines in a bar chart
我正在折線圖中畫一些線。 如果 y 軸上的任何值超過 250 或 -250,我希望已繪制的線條調整大小。 我該怎么做?
function display(data){
var maxY = d3.max(data, function(c) {
return d3.max(c.values, function(d) {
return Math.abs(d.corriente);
});
});
if(maxY>limit){
y.domain([-maxY, maxY]);
svg.select(".axisX")
.transition()
.duration(750)
.ease("sin-in-out")
.call(xAxis);
svg.select(".axisY")
.transition()
.duration(750)
.ease("sin-in-out")
.call(yAxis);
}
var path = g.selectAll(null)
.data(oData, function(d) { return d.ciclo; })
.enter()
.append("path")
.attr("d", function(d) {
return line(d.values)
})
.attr("class", function(d) {
return "line " + d.ciclo;
})
path.each(function(d) {
var totalLength = this.getTotalLength();
d3.select(this)
.attr("stroke-dasharray", totalLength + " " + totalLength)
.attr("stroke-dashoffset", totalLength)
.transition()
.duration(4000)
.attr("stroke-dashoffset", 0);
})
}
display(oData);
您需要更新現有路徑:
g.selectAll(".line")
.transition()
.duration(750)
.attr("d", function(d) {
return line(d.values)
})
這是更新的 plunker: http ://plnkr.co/edit/w0INQyy3hEcuzvP5J8FR?p=preview
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.