Published
Edited
Oct 16, 2019
Insert cell
md`# Intro to Vega-Lite`
Insert cell
500 * 10
Insert cell
coffee = 3
Insert cell
total = coffee * 5
Insert cell
color = "orange"
Insert cell
`My favorite color is ${color}`
Insert cell
html`<span style="background:yellow;">My favorite language is <i>HTML</i></span>.`
Insert cell
md`My favorite color is **${color}**.`
Insert cell
Insert cell
Insert cell
data = require('vega-datasets')
Insert cell
cars = data['cars.json']()
Insert cell
printTable(cars.slice(0,5))
Insert cell
// http://bit.ly/weather-vega
df = [
{"city": "Seattle", "month": "Apr", "precip": 2.68},
{"city": "Seattle", "month": "Aug", "precip": 0.87},
{"city": "Seattle", "month": "Dec", "precip": 5.31},
{"city": "New York", "month": "Apr", "precip": 3.94},
{"city": "New York", "month": "Aug", "precip": 4.13},
{"city": "New York", "month": "Dec", "precip": 3.58},
{"city": "Chicago", "month": "Apr", "precip": 3.62},
{"city": "Chicago", "month": "Aug", "precip": 3.98},
{"city": "Chicago", "month": "Dec", "precip": 2.56},
{"city": "Pittsburgh", "month": "Apr", "precip": 3.10},
{"city": "Pittsburgh", "month": "Aug", "precip": 3.50},
{"city": "Pittsburgh", "month": "Dec", "precip": 2.90},
];
Insert cell
printTable(df)
Insert cell
vl.markPoint()
.data(df)
.encode(vl.y().field('city').type('nominal'))
.render()
Insert cell
vl.markPoint()
.data(df)
.encode(
vl.y().fieldN('city'),
vl.x().fieldQ('precip')
)
.render()
Insert cell
vl.markPoint()
.data(df)
.encode(
vl.y().fieldN('city'),
vl.x().average('precip')
)
.render()
Insert cell
vl.markBar()
.data(df)
.encode(
vl.y().fieldN('city'),
vl.x().average('precip')
)
.render()
Insert cell
vl.markBar()
.data(df)
.encode(
vl.x().fieldN('city'),
vl.y().average('precip')
)
.render()
Insert cell
vl.markPoint()
.data(df)
.encode(
vl.y().fieldN('city'),
vl.color().fieldN('city'),
vl.x().fieldQ('precip').scale({type: 'log'}).title('Precipitation')
)
.render()
Insert cell
vl.markPoint()
.data(df)
.encode(
vl.y().fieldN('city'),
vl.color().fieldQ('precip'),
vl.x().fieldQ('precip').title('Precipitation')
)
.render()
Insert cell
printTable(cars.slice(0,5))
Insert cell
vl.markPoint()
.data(cars)
.encode(
vl.x().fieldQ('Horsepower'),
vl.y().fieldQ('Miles_per_Gallon'),
vl.color().fieldN('Origin'),
vl.tooltip(['Name', 'Origin'])
)
.render()
Insert cell
viewof hpMin = html`<input type=range />`;
Insert cell
hpMin
Insert cell
Insert cell
Insert cell
vl.markPoint()
.data(dataJapan)
.encode(
vl.x().fieldQ('Horsepower'),
vl.y().fieldQ('Miles_per_Gallon'),
vl.color().fieldN('Origin'),
vl.tooltip(['Name', 'Origin'])
)
.render()
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