Published
Edited
Jan 8, 2021
2 forks
Importers
Insert cell
Insert cell
Insert cell
// selectedCountry = ["France", "Portugal"]
selectedCountry = ["France", "Portugal", "Italy", "Germany", "Finland", "Denmark", "Norway", "Netherlands", "Spain", "United Kingdom", "Greece"]
Insert cell
Insert cell
euData = countryNaRate.filter(d => d.continent === 'Europe')
Insert cell
groupBySelectedCountry = d3.group(euData, d => d.country)
Insert cell
groupBySelectedCountry3 = d3.group(selectedCountryData, d => d.country)
Insert cell
countryNaRate
Insert cell
// chart = {
// const svg = d3.create("svg")
// .attr("viewBox", [0, 0, width, height]);
// svg.selectAll("rect")
// .data(selectedCountryData)
// .join('rect')
// .attr('x', (d,i) => {console.log(i); return(i * 8)})
// .attr('y', 100)
// .attr('width', 5)
// .attr('height', 5)
// .attr('fill', d => colorScale(d['rate']))
// return svg.node();
// }
Insert cell
function colNameMaker(){
let columnNamesContainer = []

groupBySelectedCountry3.get("Germany").forEach(d => {
console.log("----------")
console.log(d['col_name'])
columnNamesContainer.push(d['col_name'])
})

const columnNames = [...new Set(columnNamesContainer)]
return columnNames
}
Insert cell
columnNames = colNameMaker()
Insert cell
xScale = d3.scaleBand()
.domain(Array.from(groupBySelectedCountry.keys()))
.range([margin.left, width - margin.right])
.padding(0)
.align(0.5)
.round(true)
Insert cell
yScale = d3.scaleBand()
.domain(columnNames)
.range([margin.top, height - margin.bottom - margin.top])
.padding(0.2)
// .align(0.62)
.round(true)
Insert cell
chart2 = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]); // min-x, min-y, width, height

groupBySelectedCountry.forEach((d,i,e)=> {
console.log("==============")
// console.log(d[1]['col_name'])
// console.log(`rect.ind-${i}`)
// console.log(e)
svg.selectAll(`rect.${i}`) // to give unique names, i -> country
.data(groupBySelectedCountry.get(i))
.join('rect')
.attr('y', d => yScale(d['col_name']))
.attr('x', xScale(i))
.attr('width', xScale.bandwidth() * 0.95)
.attr('height', yScale.bandwidth())
.attr('fill', d => colorScale(d['rate']))
})
const xAxis = svg.append("g")
.attr("id", "xAxisG")
.attr("transform", `translate(0 ,${margin.top + 20})`)
.call(d3.axisTop(xScale))
.attr("font-size", 5)
.call(g => g.select(".domain")
.remove())

xAxis.selectAll("text")
.attr("transform", `translate(8, 0) rotate(-90)`)
.style("text-anchor", "start")

svg.append("g")
.attr("transform", `translate(${margin.left}, 0)`)
.call(d3.axisLeft(yScale))
.attr("font-size", 5)
.call(g => g.select(".domain")
.remove())

return svg.node();
}
Insert cell
groupBySelectedCountry
Insert cell
groupBySelectedCountry.get("France")
Insert cell
Array.from( groupBySelectedCountry.keys())
Insert cell
Insert cell
xScale('Germany')
Insert cell
euData.indexOf('Spain')

Insert cell
yScale('icu_patients')
Insert cell
Insert cell
Insert cell
height = 600
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more