chart1 = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
if (movie_or_series == "Movie") {
svg
.append("text")
.attr("class", "text")
.attr("transform", "translate(500,50)")
.style("text-anchor", "middle")
.style("font-size", "25px")
.style("font-weight", "bold")
.text("Count of ratings by genre for Disney movies");
const x_movie = d3
.scaleBand()
.domain(genre_movie.map(d => d.genre))
.range([margin.left, width - margin.right]);
const y_movie = d3
.scaleLinear()
.domain([d3.max(genre_movie, d => d.rating), 0])
.range([margin.bottom, height - margin.top]);
const xAxis_movies = g =>
g
.call(d3.axisBottom(x_movie))
.attr('transform', `translate(0, ${height - margin.bottom + 10})`);
const yAxis_movie = g =>
g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y_movie));
x_movie.padding(0.2);
svg
.append('g')
.call(xAxis_movies)
.selectAll("text")
.style("text-anchor", "end")
.attr("dx", "-.8em")
.attr("dy", ".15em")
.attr("transform", "rotate(-65)");
svg.append('g').call(yAxis_movie);
svg
.selectAll('.bar')
.data(genre_movie)
.join(enter => enter.append("rect"))
.attr('x', d => x_movie(d.genre))
.attr('y', d => y_movie(d.rating))
.attr('width', x_movie.bandwidth())
.attr('height', d => y_movie(0) - y_movie(d.rating))
.attr('fill', "purple")
.attr('opacity', 0.7);
} else {
//title
svg
.append("text")
.attr("class", "text")
.attr("transform", "translate(500,50)")
.style("text-anchor", "middle")
.style("font-size", "25px")
.style("font-weight", "bold")
.text("Count of ratings by genre for Disney series");
//set x
const x_series = d3
.scaleBand()
.domain(genre_series.map(d => d.genre))
.range([margin.left, width - margin.right]);
//set y
const y_series = d3
.scaleLinear()
.domain([d3.max(genre_series, d => d.rating), 0])
.range([margin.bottom, height - margin.top]);
//setxAxis
const xAxis_series = g =>
g
.call(d3.axisBottom(x_series))
.attr('transform', `translate(0, ${height - margin.bottom + 10})`);
const yAxis_series = g =>
g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y_series));
x_series.padding(0.2);
svg
.append('g')
.call(xAxis_series)
.selectAll("text")
.style("text-anchor", "end")
.attr("dx", "-.8em")
.attr("dy", ".15em")
.attr("transform", "rotate(-65)");
svg.append('g').call(yAxis_series);
svg
.selectAll('.bar')
.data(genre_movie)
.join(enter => enter.append("rect"))
.attr('x', d => x_series(d.genre))
.attr('y', d => y_series(d.rating))
.attr('width', x_series.bandwidth())
.attr('height', d => y_series(0) - y_series(d.rating))
.attr('fill', "red")
.attr('opacity', 0.7);
}
svg
.append("text")
.attr("class", "text")
.attr("transform", `translate(500, ${height - margin.bottom + 45})`)
.style("text-anchor", "middle")
.style("font-size", "14px")
.text("Genre");
svg
.append("text")
.attr("class", "text")
.attr("transform", `translate(10, ${height / 2})rotate(-90)`)
.style("text-anchor", "middle")
.style("font-size", "14px")
.text("Count");
return svg.node();
}