Published
Edited
Nov 16, 2021
Insert cell
Insert cell
import { vl } from "@vega/vega-lite-api"
Insert cell
Insert cell
vl.markCircle() // Make a scatter chart
.data(cars) // Using the cars data (below)
.encode(
vl.x().fieldQ("Horsepower"), // For x, use the Horsepower field
vl.y().fieldQ("Miles_per_Gallon"), // For y, use the Miles_per_Gallon field
vl.tooltip().fieldN("Name") // For tooltips, show the Name field
)
.render() // Draw the chart
Insert cell
cars = FileAttachment("cars.json").json()
Insert cell
Insert cell
Insert cell
Insert cell
cars[0]
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
vl.markBar() // Make a bar chart
.data(cars) // With the cars data again
.encode(
vl.y().fieldN("Origin"), // y can come before x: different orders won't break anything
vl.x().count() // For x, count the number of records
)
.render() // Draw the chart
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Table(cars, { width: 660 })
Insert cell
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