Built with blockbuilder.org
Last active
May 14, 2019 15:12
-
-
Save alfmoh/47c443cd8894f76be0ee6fc935b1c9a8 to your computer and use it in GitHub Desktop.
horizontal bars
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| license: mit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!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; } | |
| .bar { | |
| shape-rendering: cripEdges; | |
| fill:purple; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <script> | |
| // Feel free to change or delete any of the code you see in this editor! | |
| var svg = d3.select("body").append("svg") | |
| .attr("width", 960) | |
| .attr("height", 500) | |
| const data = [239,453,514,432,122,512,291,301,300]; | |
| const scale = d3.scaleLinear() | |
| .domain([0,514]) | |
| .range([50,500]) | |
| // svg.selectAll("rect") | |
| // .data(data) | |
| // .enter() | |
| // .append("rect") | |
| // .attr("width",50) | |
| // .attr("height",d=>scale(d)) | |
| // .attr("y",d=>scale(500-d)) | |
| // .attr("x",(d,i)=>60 * i) | |
| // .style("fill","#FE9922") | |
| // .style("stroke", "#9A8B7A") | |
| // .style("stroke-width", "1px") | |
| // const xAxis = d3.axisBottom(scale) | |
| // svg.append("g") | |
| // .call(xAxis) | |
| // .attr("transform",`translate(-45,450)`) | |
| svg.selectAll("rect.bar") | |
| .data(data) | |
| .enter() | |
| .append("rect") | |
| .classed("bar",true) | |
| .attr("width",d=>scale(d)) | |
| .attr("height",48) | |
| .attr("x",(d,i)=>5) | |
| .attr("y",(d,i)=>50*i) | |
| </script> | |
| </body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment