Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

Document

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

image text in transcribed

Illut

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual Basic6 Database Programming

Authors: John W. Fronckowiak, David J. Helda

1st Edition

0764532545, 978-0764532542

More Books

Students also viewed these Databases questions