Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function updateBars(divId, jobData, year, occCode)
  2. {
  3.     // write code to update the bar chart created to the specified year
  4.     // you should use two transitions, one to update the bar values
  5.     // and the other to reorder the bars
  6.     // Make sure to transition the axes, too!
  7.    
  8.     var svg = d3.select(divId).append("svg")
  9.         .attr("width", barW+barMargin.left+barMargin.right)
  10.         .attr("height", barH+barMargin.top+barMargin.bottom)
  11.         .append("g")
  12.         .attr("class", "main")
  13.         .attr("transform",
  14.               "translate(" + barMargin.left + "," + barMargin.top + ")")
  15.  
  16.         var csData = extractJobsPct(jobData, year);
  17.  
  18.         barX.range([0,barW])
  19.         .domain(csData.map(function(d) { return d.area_title; }));
  20.         barY.range([barH,0])
  21.         .domain([0,d3.max(extractJobsPct(jobData, null),
  22.                   function(d) { return +d.jobs_1000; })]);
  23.  
  24.         svg.selectAll("rect")
  25.         .data(csData)
  26.         .enter().append("rect")
  27.         .style("fill", "blue")
  28.         .attr("class", "bar")
  29.         .attr("x", function(d) { return barX(d.area_title); })
  30.         .attr("y", function(d) { return barY(+d.jobs_1000); })
  31.         .attr("width", barX.bandwidth())
  32.         .attr("height", function(d) { return barH - barY(+d.jobs_1000); })
  33.  
  34.         barXAxis = d3.axisBottom(barX);
  35.  
  36.         svg.append("g")
  37.         .attr("transform", "translate(0," + barH +")")
  38.         .attr("class", "x axis")
  39.         .call(barXAxis)
  40.  
  41.         var barYAxis = d3.axisLeft(barY);
  42.  
  43.         svg.append("g")
  44.         .attr("class", "y axis")
  45.         .call(barYAxis)
  46.  
  47.         svg.append("g")
  48.         .attr("transform", "translate(-30," + (barH/2) + ") rotate(-90)")
  49.         .append("text")
  50.         .style("text-anchor", "middle")
  51.         .text("Jobs Per 1000")
  52.  
  53.         svg.append("text")
  54.         .attr("x", barW/2)
  55.         .attr("y", barH + 115)
  56.         .text("State")
  57.    
  58.    
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement