Note that there are some explanatory texts on larger screens.

plurals
  1. POD3 transitions on more than 1 svg element
    primarykey
    data
    text
    <p>I am new to D3 and trying to learn a few basics. I've been using the D3 tips and Tricks book and tried to adapt a line graph to get a couple of lines into it which both transition. The basic idea is that Line A starts off with Data A, Line B with Data B. Then on clicking a button, Line A transitions to Data C and Line B to Data D. </p> <p>The line graph is an over time graph so I've set the x axis to be a time axis. </p> <p>Here's the code I'm using (cut down a bit)</p> <pre><code> // Define the axes var xAxis = d3.svg.axis().scale(x) .orient("bottom").ticks(10); var yAxis = d3.svg.axis().scale(y) .orient("left").ticks(5); // Define the line var valueline = d3.svg.line() .x(function(d) { return x(d.date); }) .y(function(d) { return y(d.number); }); // Define the line var valueline2 = d3.svg.line() .x(function(d) { return x(d.date); }) .y(function(d) { return y(d.number2); }); // Define the line var valueline3 = d3.svg.line() .x(function(d) { return x(d.date); }) .y(function(d) { return y(d.number3); }); // Define the line var valueline4 = d3.svg.line() .x(function(d) { return x(d.date); }) .y(function(d) { return y(d.number4); }); // Adds the svg canvas var svg = d3.select("body") .append("svg") .attr("width", width + margin.left + margin.right) .attr("height", height + margin.top + margin.bottom) .append("g") .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); // Get the data d3.tsv("data/data3.tsv", function(error, data) { d.date = parseDate(d.date); d.number = +d.number; d.number2 = +d.number2; d.number3 = +d.number3; d.number4 = +d.number4; d.number5 = +d.number5; }); // Scale the range of the data x.domain(d3.extent(data, function(d) { return d.date; })); y.domain([0, d3.max(data, function(d) { return d.number4; })]); // Add the path. svg.append("path") .attr("d", valueline(data)); //Add the transition for the first line d3.select("p2") .on("click", function() { svg.select("path") .data(data) .transition() .delay(function(d, i) { return i / 40 * 1000; }) .duration(1500) .attr("d", valueline3(data)); }) ; // Add the second path. svg.append("path") .attr("d", valueline2(data)) //Add the transition for the second line d3.select("p3") .on("click", function() { svg.select("path") .data(data) .transition() .delay(function(d, i) { return i / 40 * 1000; }) .duration(1500) .attr("d", valueline4(data)); }) </code></pre> <p>The problem is that oth transitions end up applying to the first line, with the second one static What am I doing wrong? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload