Built with blockbuilder.org
| <!DOCTYPE html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script> | |
| <style> | |
| div{ | |
| width: 50px; | |
| height: 50px; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <script> | |
| var divs = d3.select('body').selectAll('div') | |
| .data([ | |
| {foo: 1, bar: 3, color: 'red'}, | |
| {foo: 2, bar: 2, color: 'blue'}, | |
| {foo: 3, bar: 1, color: 'green'} | |
| ]) | |
| .enter().append('div') | |
| .style({ | |
| 'background-color': function(d){ return d.color; } | |
| }); | |
| divs.sort(function(a, b){ var sortKey = 'foo'; return a[sortKey] - b[sortKey]; }); | |
| </script> | |
| </body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment