Notebooks 2.0 is here.

Public
Edited
Nov 8, 2021
Insert cell
Insert cell
- Cell (Markdown / HTML / JS Code)
- Output of the Cell (Coming on Top)
- Label the Cell also
Insert cell
Insert cell
Insert cell
Insert cell
a = 6
Insert cell
b = 3
Insert cell
a * b
Insert cell
Insert cell
c = "hello"
Insert cell
d = "world"
Insert cell
m = c + " " + d
Insert cell
## Functions

- Built-in Function (String, Number) by the language
- Create Function on our own
- Import function from libraries (d3, vl)
Insert cell
// Convert to Upper Case
m.toUpperCase()
Insert cell
// Create my own function
function multiply(a, b) {
return a * b;
}
Insert cell
multiply(2, 3)
Insert cell
multiply("a", "b")
Insert cell
Insert cell
sales = [5, 25, 10, 20, 15]
Insert cell
// First Number
sales[0]
Insert cell
// Number of items in the Array
sales.length
Insert cell
Insert cell
people = ({ name: "Akshita", handle: "@aksh" })
Insert cell
people.name
Insert cell
people.handle
Insert cell
Object.keys(people)
Insert cell
Object.values(people)
Insert cell
Insert cell
// Column Way
dataColumns = ({
area: ["north", "east", "west", "south", "central"],
sales: [5, 15, 10, 20, 15],
profit: [2, 8, 6, 5, 3]
})
Insert cell
// Row Way
dataRow = [
{ area: "north", sales: 5, profit: 2 },
{ area: "east", sales: 25, profit: 8 },
{ area: "west", sales: 10, profit: 6 },
{ area: "south", sales: 20, profit: 5 },
{ area: "central", sales: 15, profit: 3 }
]
Insert cell
Insert cell
textCSV = `Area,Sales,Profit
North,5,2
East,25,8
West,10,6
South,20,5
Central,15,3`
Insert cell
Insert cell
dataCSV = d3.csvParse(textCSV)
Insert cell
Insert cell
vl
.spec({
data: { values: dataRow },
mark: "bar",
encoding: {
x: { field: "area", type: "nominal" },
y: { field: "sales", type: "quantitative" }
}
})
.render()
Insert cell
vegaEmbed = require("vega-embed")
Insert cell
vegaEmbed({
data: { values: dataRow },
mark: "bar",
encoding: {
x: { field: "area", type: "N" },
y: { field: "sales", type: "Q" },
color: { field: "profit", type: "Q" }
}
})
Insert cell
vegaEmbed({
$schema: "https://vega.github.io/schema/vega-lite/v5.json",
description: "A simple bar chart with embedded data.",
data: {
values: [
{ a: "A", b: 28 },
{ a: "B", b: 55 },
{ a: "C", b: 43 },
{ a: "D", b: 91 },
{ a: "E", b: 81 },
{ a: "F", b: 53 },
{ a: "G", b: 19 },
{ a: "H", b: 87 },
{ a: "I", b: 52 }
]
},
mark: "bar",
encoding: {
x: { field: "a", type: "nominal", axis: { labelAngle: 0 } },
y: { field: "b", type: "quantitative" }
}
})
Insert cell
## One More Visualisation
Insert cell
vegaEmbed({
width: 300,
height: 300,
data: { values: dataRow },
mark: "circle",
encoding: {
x: { field: "area", type: "N" },
y: { field: "sales", type: "Q" },
color: { field: "area", type: "N" },
size: { field: "profit", type: "Q" }
}
})
Insert cell
vegaEmbed({
width: 300,
height: 300,
data: { values: dataRow },
mark: "text",
encoding: {
x: { field: "sales", type: "Q", axis: null },
y: { field: "profit", type: "Q", axis: null },
text: { field: "area", type: "N" },
color: { field: "area", type: "N" },
size: { field: "profit", type: "Q" }
},
config: { view: { stroke: null } }
})
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