Published
Edited
Oct 18, 2020
Insert cell
md`# Live Demo of VegaLite OpenVis Conf talk`
Insert cell
md`## 1. Single View Specification`
Insert cell
Insert cell
Insert cell
vegalite({
data: { values: weathers },
mark: 'tick',
encoding: {
x: { field: 'temp_max', type: 'quantitative' },
}
})
Insert cell
// Histogram
vegalite({
data: { values: weathers },
mark: 'bar',
encoding: {
x: { bin: true, field: 'temp_max', type: 'quantitative' },
y: { aggregate: 'count', type: 'quantitative' }
}
})
Insert cell
// Histogram + Color = Stack Histogram
vegalite({
data: { values: weathers },
mark: 'bar',
encoding: {
x: { bin: true, field: 'temp_max', type: 'quantitative' },
y: { aggregate: 'count', type: 'quantitative' },
color: {
field: 'weather', type: 'nominal',
scale: {
domain: ['sun', 'fog', 'drizzle', 'rain', 'snow'],
range: ['#e7ba52', '#c7c7c7', '#aec7e8', '#1f77b4', '#9467bd']
}
}
}
})
Insert cell
// line default not stack
vegalite({
data: { values: weathers },
mark: 'line',
encoding: {
x: { bin: true, field: 'temp_max', type: 'quantitative' },
y: { aggregate: 'count', type: 'quantitative' },
color: {
field: 'weather', type: 'nominal',
scale: {
domain: ['sun', 'fog', 'drizzle', 'rain', 'snow'],
range: ['#e7ba52', '#c7c7c7', '#aec7e8', '#1f77b4', '#9467bd']
}
}
}
})
Insert cell
// Histogram + Column = Trellis Histogram
vegalite({
data: { values: weathers },
mark: 'bar',
encoding: {
x: { bin: true, field: 'temp_max', type: 'quantitative' },
y: { aggregate: 'count', type: 'quantitative' },
column: { field: 'weather', type: 'nominal' },
color: {
field: 'weather', type: 'nominal',
scale: {
domain: ['sun', 'fog', 'drizzle', 'rain', 'snow'],
range: ['#e7ba52', '#c7c7c7', '#aec7e8', '#1f77b4', '#9467bd']
}
}
}
})
Insert cell
md`## 2. Layered and Muti-View Composition`
Insert cell
barSpec = ({
mark: 'bar',
encoding: {
x: { timeUnit: 'month', field: 'date', type: 'ordinal' },
y: { aggregate: 'mean', field: 'precipitation', type: 'quantitative' },
}
})
Insert cell
histogramSpec = ({
mark: 'bar',
encoding: {
x: { bin: true, field: 'temp_max', type: 'quantitative' },
y: { aggregate: 'count', type: 'quantitative' }
}
})
Insert cell
vegalite({
data: { values: weathers },
...barSpec
})
Insert cell
vegalite({
data: { values: weathers },
layer: [
barSpec,
{
mark: { type: 'rule', color: 'red', strokeWidth: 2 },
encoding: {
y: { aggregate: 'mean', field: 'precipitation', type: 'quantitative' }
}
},
]
})
Insert cell
vegalite({
data: { values: weathers },
vconcat: [ histogramSpec, barSpec ]
})
Insert cell
vegalite({
repeat: {
row: ['wind', 'precipitation', 'temp_max'],
},
spec: {
data: { values: weathers },
mark: 'bar',
encoding: {
x: { timeUnit: 'month', field: 'date', type: 'ordinal' },
y: { aggregate: 'mean', field: { repeat: 'row' }, type: 'quantitative' },
}
}
})
Insert cell
vegalite({
repeat: {
column: ['temp_max', 'precipitation', 'wind'],
row: ['wind', 'precipitation', 'temp_max'],
},
spec: {
data: { values: weathers },
mark: 'point',
encoding: {
x: { field: { repeat: 'column' }, type: 'quantitative' },
y: { field: { repeat: 'row' }, type: 'quantitative' }
}
}
})
Insert cell
md`## 3. Selections`
Insert cell
cars = data['cars.json']()
Insert cell
printTable(cars.slice(0, 5));
Insert cell
vegalite({
data: { values: cars },
mark: 'circle',
encoding: {
x: { field: 'Horsepower', type: 'Q' },
y: { field: 'Miles_per_Gallon', type: 'Q' },
color: { field: 'Origin', type: 'N' },
}
})
Insert cell
vegalite({
data: { values: cars },
mark: 'circle',
selection: {
picked: { type: 'single' }
},
encoding: {
x: { field: 'Horsepower', type: 'Q' },
y: { field: 'Miles_per_Gallon', type: 'Q' },
color: {
field: 'Origin', type: 'N',
condition: { selection: 'picked', value: 'grey' }
},
}
})
Insert cell
vegalite = require("@observablehq/vega-lite@0.3")
Insert cell
data = require('vega-datasets@2')
Insert cell
import {printTable} from '@uwdata/data-utilities'
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