Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
179 views
in Technique[技术] by (71.8m points)

javascript - generation of lines is not shown, attribute d of the path is empty

I'm trying to create lines that connect and generate an animation. I have an array of 2 positions, in each position of the array I want to generate a line from those points.

but my problem is that they are not generating, the attribute d of the path appears empty, that I am doing wrong?

enter image description here

this is my current code: http://jsfiddle.net/6vhved46/

I made a modification to my original code which was this.

http://jsfiddle.net/syckujd8/

I changed the structure of the dataset variable on this occasion.

  var svg = d3.select('svg');

  var backLayer = svg.append("g");

  var dataSet=[
    [
      { "voltaje":  Math.random() * 30 + 10, "corriente": Math.random() * 130 + 10},
      { "voltaje":  Math.random() * 30 + 10, "corriente": Math.random() * 130 + 10},
      { "voltaje":  Math.random() * 30 + 10, "corriente": Math.random() * 130 + 10}
    ],
     [
      { "voltaje":  Math.random() * 30 + 10, "corriente": Math.random() * 130 + 10},
      { "voltaje":  Math.random() * 30 + 10, "corriente": Math.random() * 130 + 10},
      { "voltaje":  Math.random() * 30 + 10, "corriente": Math.random() * 130 + 10},
      { "voltaje":  Math.random() * 30 + 10, "corriente": Math.random() * 130 + 10}

    ]
  ];
  console.log(dataSet);

  var lineGenerator = d3.svg.line()
    .x(function(d) {
      return d.corriente
    })
    .y(function(d) {
      return d.voltaje
    })
    .interpolate("monotone")

  function displayLine(data) {
    var line = backLayer.selectAll(null)
      .data(data)
      .enter()
      .append("path")
      .attr("d",function(d){
        lineGenerator(d)
      })
      .attr("fill",'none')
      .attr("stroke","red")
      .attr("stroke-width","1px")
      .attr("class","linea1");


    var totalLength = line.node().getTotalLength();

    line.attr("stroke-dasharray", totalLength + " " + totalLength)
      .attr("stroke-dashoffset", totalLength)
      .transition()
      .duration(2000)
      .ease("linear")
      .attr("stroke-dashoffset", 0);
  }

  displayLine(dataSet)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...