Published
Edited
Jun 15, 2020
Importers
Insert cell
Insert cell
data = (await require('vega-datasets'))['movies.json']()
Insert cell
heatMap = {
const chart = await vegalite({
mark: {type: "rect"},
data: {name: "values", values: transform(data) },
encoding: {
x: {
field: "col",
type: "nominal",
axis: { labelAngle: 0, title: null, orient: "top"},
sort: Object.keys(data[0])
},
y: { field: "row", type: "nominal", axis: null},
color: { field: "value", type: "nominal", sort: ["Not Missing", "Missing"], legend: {title: null, orient: "top"}}
},
width: {step: 100},
height: {step: 1}
})
return html`<div style="overflow: auto; height: ${height}px">${chart}</div>`
}
Insert cell
notNull = (value) => {
if (value) {
return "Not Missing"
} else if (value === 0) {
return "Not Missing"
} else {
return "Missing"
}
}
Insert cell
transform = (data) => {
const heatMap = []
for (let i = 0; i < data.length; i++) {
for (const prop in data[i]) {
heatMap.push({
row: i,
col: prop,
value: notNull(data[i][prop])
})
}
}
return heatMap
}
Insert cell
height = 400
Insert cell
width = 800
Insert cell
vegalite = require("@observablehq/vega-lite")
Insert cell
html`
<style>
.container {
width: ${width}px;
height: ${height}px;
overflow: auto;
}
</style>
`
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