Platform
Resources
Pricing
Sign in
Get started
Gordon Tu
Trying to get good at Three and D3 @tu_yukun
Workspace
Fork
Public
By
Gordon Tu
Edited
Mar 28, 2024
6
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
game
Clear All
Swap X/Y
Customize
X
playerFullName
Y
OBP
Color
—
Size
—
Facet X
pos
Facet Y
—
Mark
Auto
Type Chart, then Shift-Enter. Ctrl-space for more options.
Insert cell
// data = await d3.json(
// "https://project.trumedianetworks.com/api/mlb/dataviz-data-by-game/0",
// {
// headers: new Headers({
// accept: "application/json",
// tempToken: "01ffb537-7927-4b0d-a2d2-fba9382647b1"
// })
// }
// )
Insert cell
data.csv
Filter
1
Columns
53
Sort
Slice
Save
Type Table, then Shift-Enter. Ctrl-space for more options.
Insert cell
data
Clear All
Swap X/Y
Customize
X
—
Y
BA
Color
—
Size
—
Facet X
win
Facet Y
—
Mark
Auto
Type Chart, then Shift-Enter. Ctrl-space for more options.
Insert cell
data
Clear All
Swap X/Y
Customize
X
date
Y
PA
Color
home
Size
—
Facet X
—
Facet Y
—
Mark
bar
Type Chart, then Shift-Enter. Ctrl-space for more options.
Insert cell
Plot
.
plot
(
{
color
:
{
legend
:
true
,
scheme
:
"RdYlBu"
}
,
marks
:
[
Plot
.
barY
(
data
,
{
x
:
"date"
,
y
:
"PA"
,
fill
:
"home"
,
tip
:
true
}
)
,
Plot
.
ruleY
(
[
0
]
)
]
}
)
Insert cell
d3
.
extent
(
data
,
d
=>
d
.
date
)
Insert cell
data
Clear All
Swap X/Y
Customize
X
home
Y
—
Color
home
Size
—
Facet X
win
Facet Y
—
Mark
bar
Type Chart, then Shift-Enter. Ctrl-space for more options.
Insert cell
Insert cell
// Plot.plot({
// marks: [
// Plot.frame({ strokeOpacity: 0.1 }),
// Plot.ruleX([0]),
// Plot.dot(
// data,
// Plot.binY(
// { x: "count" },
// { fx: "playerFullName", fy: "opponent", y: "HR", tip: true }
// )
// )
// ]
// })
Insert cell
Insert cell
Insert cell
first_100
Filter
Columns
Sort
Slice
Save
Type Table, then Shift-Enter. Ctrl-space for more options.
Insert cell
median_avg.csv
Filter
Columns
Sort
Slice
Save
Type Table, then Shift-Enter. Ctrl-space for more options.
Insert cell
{
// Usage example
const
top10ByOpponent
=
getTopNByOpponent
(
data
,
"BB_num_mean"
,
10
)
;
return
top10ByOpponent
;
}
Insert cell
function
getTopNByOpponent
(
data
,
column
,
n
)
{
// Group data by opponent
const
groupedData
=
d3
.
group
(
data
,
(
d
)
=>
d
.
opponent
)
;
// Get top N players with the highest value for the specified column for each opponent
return
Array
.
from
(
groupedData
,
(
[
opponent
,
players
]
)
=>
{
return
{
opponent
,
topN
:
players
.
sort
(
(
a
,
b
)
=>
b
[
column
]
-
a
[
column
]
)
.
slice
(
0
,
n
)
}
;
}
)
;
}
Insert cell
Insert cell
Insert cell
video
=
FileAttachment
(
"video.json"
)
.
json
(
)
Insert cell
project1
=
FileAttachment
(
"project@1.json"
)
.
json
(
)
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.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
game
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
Cells
game
File attachments
video.json
JSON
game.json
JSON
project@1.json
JSON
first_100.json
JSON
data.csv
CSV
median_avg.csv
CSV
Customize
Clear
Title
Subtitle
Caption
Height
Width
Auto
Full
Margin
Top
Right
Bottom
Left
Inset
Legend
Auto
None
X label
X scale
Auto
Scale
Auto
linear
log
sqrt
symlog
point
band
X options
Grid
Reverse
Y label
Y scale
Auto
Scale
Auto
linear
log
sqrt
symlog
point
band
Y options
Grid
Reverse
Color scheme
Auto
Color scheme
Auto
Default color schemes
Sequential
Diverging
Cyclical
Categorical
Sequential color schemes
Blues
Greens
Greys
Oranges
Purples
Reds
Turbo
Viridis
Inferno
Magma
Plasma
Cividis
Warm
Cool
BuGn
BuPu
GnBu
OrRd
PuBuGn
PuBu
PuRd
RdPu
YlGnBu
YlGn
YlOrBr
YlOrRd
Diverging color schemes
BrBG
PRGn
PiYG
PuOr
RdBu
RdGy
RdYlBu
RdYlGn
Spectral
Cyclical color schemes
Sinebow
Turbo
Categorical color schemes
Category10
Accent
Dark2
Paired
Pastel1
Pastel2
Set1
Set2
Set3
Tableau10
Color scale
Auto
Scale
Auto
linear
log
sqrt
symlog
categorical
ordinal
Color options
Reverse
Reducer
—
Auto
—
count
distinct
sum
min
max
mean
median
mode
Field
—
Reducer
—
Auto
—
count
distinct
sum
min
max
mean
median
mode
Field
—
Reducer
—
Auto
—
count
distinct
sum
min
max
mean
median
mode
Field
—
Reducer
—
Auto
—
count
distinct
sum
min
max
mean
median
mode
Field
—
Field
—
Field
—
Mark
Auto
—
bar
dot
line
area
rule
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
data
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
File attachments
video.json
JSON
game.json
JSON
project@1.json
JSON
first_100.json
JSON
data.csv
CSV
median_avg.csv
CSV
Databases
Filter
playerFullName
Operator
Column
Operator
Columns
Sort
Column
Direction
Descending
Ascending
Slice
From
Start
To
End
Add comment
Select
Duplicate
Copy link
Embed
Delete
Cells
data
File attachments
video.json
JSON
game.json
JSON
project@1.json
JSON
first_100.json
JSON
data.csv
CSV
median_avg.csv
CSV
Customize
Clear
Title
Subtitle
Caption
Height
Width
Auto
Full
Margin
Top
Right
Bottom
Left
Inset
Legend
Auto
None
X label
X scale
Auto
Scale
Auto
linear
log
sqrt
symlog
point
band
X options
Grid
Reverse
Y label
Y scale
Auto
Scale
Auto
linear
log
sqrt
symlog
point
band
Y options
Grid
Reverse
Color scheme
Auto
Color scheme
Auto
Default color schemes
Sequential
Diverging
Cyclical
Categorical
Sequential color schemes
Blues
Greens
Greys
Oranges
Purples
Reds
Turbo
Viridis
Inferno
Magma
Plasma
Cividis
Warm
Cool
BuGn
BuPu
GnBu
OrRd
PuBuGn
PuBu
PuRd
RdPu
YlGnBu
YlGn
YlOrBr
YlOrRd
Diverging color schemes
BrBG
PRGn
PiYG
PuOr
RdBu
RdGy
RdYlBu
RdYlGn
Spectral
Cyclical color schemes
Sinebow
Turbo
Categorical color schemes
Category10
Accent
Dark2
Paired
Pastel1
Pastel2
Set1
Set2
Set3
Tableau10
Color scale
Auto
Scale
Auto
linear
log
sqrt
symlog
categorical
ordinal
Color options
Reverse
Reducer
—
Auto
—
count
distinct
sum
min
max
mean
median
mode
Field
—
Reducer
—
Auto
—
count
distinct
sum
min
max
mean
median
mode
Field
—
Reducer
—
Auto
—
count
distinct
sum
min
max
mean
median
mode
Field
—
Reducer
—
Auto
—
count
distinct
sum
min
max
mean
median
mode
Field
—
Field
—
Field
—
Mark
Auto
—
bar
dot
line
area
rule
Add comment
Select
Duplicate
Copy link
Embed
Delete
Cells
data
File attachments
video.json
JSON
game.json
JSON
project@1.json
JSON
first_100.json
JSON
data.csv
CSV
median_avg.csv
CSV
Customize
Clear
Title
Subtitle
Caption
Height
Width
Auto
Full
Margin
Top
Right
Bottom
Left
Inset
Legend
Auto
None
X label
X scale
Auto
Scale
Auto
linear
log
sqrt
symlog
point
band
X options
Grid
Reverse
Y label
Y scale
Auto
Scale
Auto
linear
log
sqrt
symlog
point
band
Y options
Grid
Reverse
Color scheme
RdYlBu
Color scheme
Auto
Default color schemes
Sequential
Diverging
Cyclical
Categorical
Sequential color schemes
Blues
Greens
Greys
Oranges
Purples
Reds
Turbo
Viridis
Inferno
Magma
Plasma
Cividis
Warm
Cool
BuGn
BuPu
GnBu
OrRd
PuBuGn
PuBu
PuRd
RdPu
YlGnBu
YlGn
YlOrBr
YlOrRd
Diverging color schemes
BrBG
PRGn
PiYG
PuOr
RdBu
RdGy
RdYlBu
RdYlGn
Spectral
Cyclical color schemes
Sinebow
Turbo
Categorical color schemes
Category10
Accent
Dark2
Paired
Pastel1
Pastel2
Set1
Set2
Set3
Tableau10
Color scale
Auto
Scale
Auto
linear
log
sqrt
symlog
categorical
ordinal
Color options
Reverse
Reducer
—
Auto
—
count
distinct
sum
min
max
mean
median
mode
Field
—
Reducer
—
Auto
—
count
distinct
sum
min
max
mean
median
mode
Field
—
Reducer
—
Auto
—
count
distinct
sum
min
max
mean
median
mode
Field
—
Reducer
—
Auto
—
count
distinct
sum
min
max
mean
median
mode
Field
—
Field
—
Field
—
Mark
Auto
bar
dot
line
area
rule
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
Cells
data
File attachments
video.json
JSON
game.json
JSON
project@1.json
JSON
first_100.json
JSON
data.csv
CSV
median_avg.csv
CSV
Customize
Clear
Title
Subtitle
Caption
Height
Width
Auto
Full
Margin
Top
Right
Bottom
Left
Inset
Legend
Auto
None
X label
X scale
Auto
Scale
Auto
linear
log
sqrt
symlog
point
band
X options
Grid
Reverse
Y label
Y scale
Auto
Scale
Auto
linear
log
sqrt
symlog
point
band
Y options
Grid
Reverse
Color scheme
BrBG
Color scheme
Auto
Default color schemes
Sequential
Diverging
Cyclical
Categorical
Sequential color schemes
Blues
Greens
Greys
Oranges
Purples
Reds
Turbo
Viridis
Inferno
Magma
Plasma
Cividis
Warm
Cool
BuGn
BuPu
GnBu
OrRd
PuBuGn
PuBu
PuRd
RdPu
YlGnBu
YlGn
YlOrBr
YlOrRd
Diverging color schemes
BrBG
PRGn
PiYG
PuOr
RdBu
RdGy
RdYlBu
RdYlGn
Spectral
Cyclical color schemes
Sinebow
Turbo
Categorical color schemes
Category10
Accent
Dark2
Paired
Pastel1
Pastel2
Set1
Set2
Set3
Tableau10
Color scale
Auto
Scale
Auto
linear
log
sqrt
symlog
categorical
ordinal
Color options
Reverse
Reducer
—
Auto
—
count
distinct
sum
min
max
mean
median
mode
Field
—
Reducer
—
Auto
—
count
distinct
sum
min
max
mean
median
mode
Field
—
Reducer
—
Auto
—
count
distinct
sum
min
max
mean
median
mode
Field
—
Reducer
—
Auto
—
count
distinct
sum
min
max
mean
median
mode
Field
—
Field
—
Field
—
Mark
Auto
bar
dot
line
area
rule
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
first_100
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
Cells
first_100
File attachments
video.json
JSON
game.json
JSON
project@1.json
JSON
first_100.json
JSON
data.csv
CSV
median_avg.csv
CSV
Databases
Filter
Column
Operator
Columns
Sort
Column
Direction
Descending
Ascending
Slice
From
Start
To
End
median_avg
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
File attachments
video.json
JSON
game.json
JSON
project@1.json
JSON
first_100.json
JSON
data.csv
CSV
median_avg.csv
CSV
Databases
Filter
Column
Operator
Columns
Sort
Column
Direction
Descending
Ascending
Slice
From
Start
To
End
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
getTopNByOpponent
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
video
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
project1
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML