Published
Edited
Apr 26, 2019
1 star
Insert cell
Insert cell
2 * 3 * 7
Insert cell
{
let sum = 10;
for (let i=0; i<100; i++) {
sum += 1;
}
return sum;
}
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 language is **Markdown**.`
Insert cell
html`My favorite color is <i style="background:${color};">${color}</i>.`
Insert cell
import {vl} from '@vega/vega-lite-api'
Insert cell
import {printTable} from '@uwdata/data-utilities'
Insert cell
data = require('vega-datasets')
Insert cell
cars = data['cars.json']()
Insert cell
printTable(cars.slice(0,5))
Insert cell
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().fieldN('city'))
.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({color: 'firebrick'})
.data(df)
.encode(
vl.y().fieldN('city').title('City'),
vl.x().fieldQ('precip').scale({type: 'log'}).title('Log-scaled 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
dataJapan = cars.filter(d => d.Origin === 'Japan')
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