Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let students = [
- {"name": "Jane", "score": 80},
- {"name": "John", "score": 90},
- {"name": "Bob", "score": 60}
- ];
- let minScore = 0;
- let maxScore = 100;
- let barWidth = 50;
- let maxHeight = 200;
- let margin = 10;
- let svg = document.getElementById("chart");
- let spec = "http://www.w3.org/2000/svg";
- students.forEach(function(student, i) {
- let rect = document.createElementNS(spec, "rect");
- let height = student.score / maxScore * maxHeight;
- rect.setAttribute("width", barWidth);
- rect.setAttribute("height", height);
- rect.setAttribute("x", (barWidth + margin) * i);
- rect.setAttribute("y", maxHeight - height);
- rect.style.fill = "steelblue";
- svg.appendChild(rect);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement