D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
areologist
Full window
Github gist
select: update, enter, exit, merge
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v4.min.js"></script> <style> body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } </style> </head> <body> <div class="chart"> <div>Billy</div> <div>Cindy</div> <div>Walter</div> </div> <script> const scores = [ { name: 'Alice', score: 96 }, { name: 'Billy', score: 83 }, { name: 'Cindy', score: 91 }, { name: 'David', score: 96 }, { name: 'Emily', score: 88 } ]; const update = d3.select('.chart') .selectAll('div') .data(scores, (d, i, n) => d ? d.name : n[i].innerText ) .style('color', 'blue'); const enter = update.enter() .append('div') .text(d => d.name) .style('color', 'green'); const exit = update.exit() .style('color', 'red'); update.merge(enter) .style('font-style', 'italic'); update.merge(exit) .style('font-weight', 'bold'); </script> </body>
https://d3js.org/d3.v4.min.js