Question
Improve the below code: By adding: 1. Main Title : Quantity Sold of Electronic Product 2. X-axis: Electronic Product 3. Y-axis: Quantity Sold Code: Document
Improve the below code:
By adding:
1. Main Title : Quantity Sold of Electronic Product
2. X-axis: Electronic Product
3. Y-axis: Quantity Sold
Code:
var margin = {top: 30, right: 30, bottom: 70, left: 60},
width = 460 - margin.left - margin.right,
height = 400 - margin.top - margin.bottom;
var svg = d3.select("#my_dataviz")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + + margin.bottom).append("g")
.attr("transform","translate("+ margin.left + "," + margin.top + ")");
d3.csv("electronics.csv", function(data) {
var x = d3.scaleBand()
.range([ 0, width ])
.domain(data.map(function(d) { return d.Product; }))
.padding(0.2);
svg.append("g")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x))
.selectAll("text")
.attr("transform", "translate(-10,0)rotate(-45)")
.style("text-anchor", "end");
var y = d3.scaleLinear()
.domain([0, 30])
.range([ height, 0]);
svg.append("g")
.call(d3.axisLeft(y));
svg.selectAll("mybar")
.data(data)
.enter()
.append("rect")
.attr("x", function(d) { return x(d.Product); })
.attr("y", function(d) { return y(d.Unit); })
.attr("width", x.bandwidth())
.attr("height", function(d) { return height - y(d.Unit); })
.attr("fill", " #0D1D74")
})
Output of the graph before improve the code by adding main title, x -axis and y-axis
IllutStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started