Notebooks 2.0 is here.

Published
Edited
Feb 18, 2019
Insert cell
md`# Starting with Vis Learning
## Basic HTML and Vis

Lets start with writing HTML
`
Insert cell
html`
<h2> Hello HTML </h2>
<p> This is in html </p>
`
Insert cell
md`
## Hello MD
This is in markdown.
`
Insert cell
Insert cell
Insert cell
x = 44
Insert cell
x
Insert cell
text = "Meaning of life"
Insert cell
Insert cell
a = [5, 10, 15, 25, 35]
Insert cell
// Accessing the first value of the array
a[0]
Insert cell
Insert cell
myObject = ({
"name": "Adam",
"year": "1980",
"style": "Humour"
})
Insert cell
// Accessing the any key for an object
myObject.name
Insert cell
Insert cell
dataset = [
{"name": "Adam", "year": "1980", "style": "Humour"},
{"name": "Laura", "year": "1990", "style": "Science"},
{"name": "Fred", "year": "19950", "style": "Business"}
]
Insert cell
dataset[1].name
Insert cell
Insert cell
data = [
{"area": "North", "sales": 5, "profit": 2},
{"area": "East", "sales": 25, "profit": 8},
{"area": "West", "sales": 15, "profit": 6},
{"area": "South", "sales": 20, "profit": 5},
{"area": "Central", "sales": 10, "profit": 3}
]
Insert cell
Insert cell
function square (x) {
return x*x
}
Insert cell
square(4)
Insert cell
Insert cell
// Importing Libraries to use
vegalite = require("vega-embed")
Insert cell
vegalite({
width: 250,
height: 250,
data: {values: data},
mark: "bar",
encoding: {
x: {field: "area", type: "nominal"},
y: {field: "sales", type: "quantitative"},
color: {field: "profit", "type": "quantitative"}
}
})
Insert cell
vegalite({
width: 250,
height: 250,
data: {values: data},
mark: "bar",
encoding: {
x: {field: "area", type: "nominal", sort: "descending"},
y: {field: "sales", type: "quantitative"},
color: {field: "profit", "type": "quantitative"}
}
})
Insert cell
vegalite({
width: 250,
height: 250,
data: {values: data},
mark: "bar",
encoding: {
x: {field: "area", type: "nominal", sort: {field: "sales", op: "sum"}},
y: {field: "sales", type: "quantitative"},
color: {field: "profit", "type": "quantitative"}
}
})
Insert cell
vegalite({
data: {values: data},
mark: "rect",
encoding: {
x: {field: "profit", type: "Q"},
y: {field: "sales", type: "Q"},
color: {field: "area", type: "N"},
opacity: {value: 0.5}
}
})
Insert cell
vegalite({
data: {values: data},
mark: "text",
encoding: {
x: {field: "sales", type: "Q"},
y: {field: "profit", type: "Q"},
text: {field: "area", type: "N"}
}
})
Insert cell
Insert cell
vegalite({
data: {values: data},
transform:[
{calculate: "datum.profit / datum.sales", as: "profitPer"}
],
mark: "bar",
encoding: {
x: {field: "area", type: "N"},
y: {field: "sales", type: "Q"},
color: {field: "profitPer", type: "Q"}
}
})
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