From a4d4fbe60510543ef4b47d83b457f804ab9fc1e2 Mon Sep 17 00:00:00 2001 From: Brady Bodily Date: Tue, 1 Oct 2019 16:59:27 -0600 Subject: [PATCH] working on color --- hw4/js/barChart.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hw4/js/barChart.js b/hw4/js/barChart.js index 3148f21..c813ac6 100644 --- a/hw4/js/barChart.js +++ b/hw4/js/barChart.js @@ -31,15 +31,16 @@ class BarChart { let yaxisWidth = 60; d3.select("#barChart") .attr("transform", "scale(1,-1)"); - console.log(data); data.sort(function(a, b) { return a[1] > b[1] ? 1 : -1; }); - console.log(data); + + let dataNum = []; data.forEach(x => dataNum.push(x.data)); let datadate = []; data.forEach(x => datadate.push(x.date)); + var blues = d3.scaleOrdinal(d3.schemeBlues[datadate.length]); let yScale = d3.scaleLinear() .domain([0 , d3.max(dataNum)]) @@ -85,6 +86,11 @@ class BarChart { .attr('width', xScale.bandwidth()) .attr('height', (d,i) => svgHeight - yScale(dataNum[i])-xaxisHeight) .attr('class', 'bar'); + console.log(blues); + + d3.select("#bars") + .selectAll('rect') + .attr('fill', (d, i) => blues[i]); // // barChart.exit().remove();