Published
Edited
Jul 1, 2022
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
colors=["#e8e8e8", "#b0d5df","#64acbe", "#e4acac", "#c85a5a", "#574249"]
Insert cell
swatches(colors)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
swissEnergy = FileAttachment("swiss-energy-with-canton.json").json()
Insert cell
data = swissEnergy.results.bindings
Insert cell
municipalityData = new Map(data.map(x=> [x.d_municipality_id.value, x.d_total.value]))
Insert cell
cantonAvg = d3.rollup(data, v => {
return d3.mean(v, d=>+d.d_total?.value??0)
}, d => +d.d_canton_id?.value ?? 0)
Insert cell
cantonEnergyData = d3.group(data, d => d.d_canton_id?.value ?? 0)
Insert cell
Insert cell
mapData = ch_url
Insert cell
dataUrl = "https://swiss-maps-git-maintainance-ixt1.vercel.app/api/v0?year=2022&shapes=country,cantons,lakes"
Insert cell
Insert cell
Insert cell
Insert cell
ch_url = d3.json(dataUrl)
Insert cell
Insert cell
ch_file = FileAttachment("ch.topojson.json").json()
Insert cell
Insert cell
function swatches(colors) {
return html`${colors.map(c => `<div title="${c}" style="
display: inline-block;
margin-right: 3px;
width: 33px;
height: 33px;
background: ${c};
"></div>`)}`;
}
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more