A scaleSequential example.
From D3 in Depth book by Peter Cook.
| license: gpl-3.0 | |
| height: 90 | |
| border: no |
A scaleSequential example.
From D3 in Depth book by Peter Cook.
| <!DOCTYPE html> | |
| <meta charset="utf-8"> | |
| <head> | |
| <title>Sequential scale</title> | |
| </head> | |
| <style> | |
| body { | |
| font-family: "Helvetica Neue", Helvetica, sans-serif; | |
| font-size: 14px; | |
| color: #333; | |
| } | |
| </style> | |
| <body> | |
| <svg width="700" height="80"> | |
| <g id="wrapper" transform="translate(40, 40)"> | |
| </g> | |
| </svg> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.2/d3.min.js"></script> | |
| <script> | |
| var linearScale = d3.scaleLinear() | |
| .domain([0, 100]) | |
| .range([0, 600]); | |
| var sequentialScale = d3.scaleSequential() | |
| .domain([0, 100]) | |
| .interpolator(d3.interpolateRainbow); | |
| var myData = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]; | |
| d3.select('#wrapper') | |
| .selectAll('circle') | |
| .data(myData) | |
| .enter() | |
| .append('circle') | |
| .attr('r', 10) | |
| .attr('cx', function(d) { | |
| return linearScale(d); | |
| }) | |
| .style('fill', function(d) { | |
| return sequentialScale(d); | |
| }); | |
| </script> | |
| </body> | |
| </html> |