From fda3b6967914537dd439117f9c874c66b7fe6496 Mon Sep 17 00:00:00 2001 From: stedyyulius Date: Tue, 20 Jun 2017 19:33:45 +0700 Subject: [PATCH] showing the whole graph --- script.js | 38 ++++++++++++++++++++++++++++++++------ topscore.js | 4 ++-- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/script.js b/script.js index c3937e8..c585e19 100644 --- a/script.js +++ b/script.js @@ -7,20 +7,46 @@ const width = 750, marginLeft = 40 // Drawing area -let svg = d3.select('#results') +var svg = d3.select('#results') .append('svg') .attr('width', width) .attr('height', height) + .style(`background`,`#cacaca`) + + // Data reloading -let reload = () => { - // Your data parsing here... +function reload() { + d3.tsv(`afcw-results.tsv`,(rows)=>{ + redraw(rows) + }) } -// redraw function -let redraw = (data) => { - // Your data to graph here + +// redraw function +function redraw(data) { + const yScale = d3.scaleLinear() + .domain([0,d3.max(d3.map(dataItem=>dataItem.GoalsScored))]) + .range([0,height]) + + svg.selectAll(`rect`) + .data(data) + .enter() + .append(`rect`) + .attr(`class`,`bar`) + .attr(`fill`,`green`) + .attr(`x`,(d,i)=>{ + return i * 22 + }) + .attr(`y`,(d,i)=>{ + return height - yScale(d) - margin + }) + .attr(`width`,20) + .attr(`height`,(d)=>{ + return yScale(d.GoalsScored) + }) + // console.log(data); } reload() diff --git a/topscore.js b/topscore.js index 577851a..d8f6b39 100644 --- a/topscore.js +++ b/topscore.js @@ -1,7 +1,7 @@ /* global d3 width height */ -let fill = d3.scaleOrdinal(d3.schemeCategory20) -let leaderScale = d3.scaleLinear() +var fill = d3.scaleOrdinal(d3.schemeCategory20) +var leaderScale = d3.scaleLinear() .range([5, 40]) const draw = (words) => {