Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width">
- <title>JS Bin</title>
- </head>
- <body>
- <svg height="1000" width="1000">
- </svg>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.3/d3.min.js"></script>
- <script>
- let students = [
- {"name": "Jane", "value": 80},
- {"name": "John", "value": 90},
- {"name": "Bob", "value": 60}
- ];
- let svg = d3.select('svg');
- let maxScore = 100
- let maxHeight = 100
- let barWidth = 30
- let margin = 10
- svg.selectAll('rect')
- .data(students)
- .enter()
- .append('rect')
- .attr('width', barWidth)
- .attr('height', d => d.value / maxScore * maxHeight)
- .attr('x', (d, i) => (barWidth + margin) * i)
- .attr('y', function() {
- return maxHeight - d3.select(this).attr('height');
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement