Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Matching names and data in stackedarea_basic.html #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions graph/stackedarea_basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,10 @@ <h5>Steps:</h5>

// Stack the data: each group will be represented on top of each other
var mygroups = ["Helen", "Amanda", "Ashley"] // list of group names
var mygroup = [1,2,3] // list of group names
var stackedData = d3.stack()
.keys(mygroup)
.keys(mygroups)
.value(function(d, key){
return d.values[key].n
return d.values.find((row) => row.name === key)?.n || 0;
})
(sumstat)

Expand Down Expand Up @@ -279,7 +278,7 @@ <h5>Steps:</h5>
.data(stackedData)
.enter()
.append("path")
.style("fill", function(d) { name = mygroups[d.key-1] ; return color(name); })
.style("fill", function(d) { return color(d.key); })
.attr("d", d3.area()
.x(function(d, i) { return x(d.data.key); })
.y0(function(d) { return y(d[0]); })
Expand Down Expand Up @@ -315,14 +314,13 @@ <h5>Steps:</h5>

// Stack the data: each group will be represented on top of each other
const mygroups = ["Helen", "Amanda", "Ashley"] // list of group names
const mygroup = [1,2,3] // list of group names
const stackedData = d3.stack()
.keys(mygroup)
.keys(mygroups)
.value(function(d, key){
return d[1][key].n
return d[1].find((row) => row.name === key)?.n || 0;
})
(sumstat)

// Add X axis --> it is a date format
const x = d3.scaleLinear()
.domain(d3.extent(data, function(d) { return d.year; }))
Expand All @@ -348,7 +346,7 @@ <h5>Steps:</h5>
.selectAll("mylayers")
.data(stackedData)
.join("path")
.style("fill", function(d) { name = mygroups[d.key-1] ; return color(name); })
.style("fill", function(d) { return color(d.key); })
.attr("d", d3.area()
.x(function(d, i) { return x(d.data[0]); })
.y0(function(d) { return y(d[0]); })
Expand Down