如何更新画笔上多条线的标记? [英] how to update the markers of a multi line on a brush?

查看:79
本文介绍了如何更新画笔上多条线的标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

绘制多条线

 var city= focus.selectAll(".city")
      .data(cities)
      .enter().append("g")
      .attr("class", "city");
 var bad=city.append("path")
      .attr("class", "line")
      .attr("d", function(d) { return line(d.values); })
      .style("stroke", function(d) { return color(d.name); })
    .style("opacity",0.5);

多行标记的代码

var point = city.append("g")
    .attr("class", "line-point");

point.selectAll('.line-point')
.data(function(d){ return d.values})
.enter()
.append('circle')
.attr("cx", function(d) { return x(d.timestamp) })
.attr("cy", function(d) { return y(d.limit) })
.attr("r", 1)
.style("fill", "grey")
.on("mouseover", function(d,i) {

        div.transition()        
            .duration(200)      
            .style("opacity", .9);      
            div.html(function(){


 { return formatTime(d.timestamp) + "<br/><b>"  + d.limit+ "</b>"}
    ;})
            .style("left", (d3.event.pageX) + "px")     
            .style("top", (d3.event.pageY - 28) + "px");    
        })                  
    .on("mouseout", function(d) {       
        div.transition()        
            .duration(500)      
            .style("opacity", 0);
   }).style("pointer-events","visible");

这就是我试图在brush()函数中更新它的方式

this is how i have tried to update it in the brush() function

function brushed() {

  x.domain(brush.empty() ? x2.domain() : brush.extent());
   focus.selectAll(".valueline").attr("d",valueline);
  focus.selectAll(".dot").select("circle").attr("cx", function(d) { return x(d.timestamp); });
   focus.selectAll("g.city path.line").attr("d",function(d){return line(d.values);});
  // update markersin multi line

  focus.selectAll(".line-point").select("circle").attr("d",function(d){return (d.values);});
  focus.select(".x.axis").call(xAxis);

}

推荐答案

focus.selectAll(".line-point").selectAll("circle").attr("cx", function(d) { return x(d.timestamp); });

再次感谢@AmeliaBR

thanks @AmeliaBR once again

这篇关于如何更新画笔上多条线的标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆