Platform
Resources
Pricing
Sign in
Get started
crazyorr
Workspace
Fork
Public
By
crazyorr
Edited
Apr 21, 2024
13
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
populationByPrefecture
Filter
Columns
5
Sort
Slice
Save
Type Table, then Shift-Enter. Ctrl-space for more options.
Insert cell
addTooltips
(
Plot
.
plot
(
{
marginLeft
:
80
,
x
:
{
grid
:
true
,
tickFormat
:
"s"
}
,
color
:
{
scheme
:
"spectral"
,
domain
:
genders
,
legend
:
true
}
,
marks
:
[
Plot
.
barX
(
populationByPrefectureGender
,
{
y
:
"district"
,
x
:
"population"
,
fill
:
"gender"
,
title
:
"population"
,
sort
:
{
y
:
"x"
,
reverse
:
true
}
}
)
,
Plot
.
ruleX
(
[
0
]
)
]
}
)
)
Insert cell
chart
=
PieChart
(
populationByPrefecture
,
{
name
:
d
=>
d
[
"地区"
]
,
value
:
d
=>
d
[
"男"
]
+
d
[
"女"
]
,
}
)
Insert cell
addTooltips
(
Plot
.
plot
(
{
projection
:
{
type
:
"albers"
,
rotate
:
[
-
110
,
0
]
,
domain
:
prefectures
}
,
marks
:
[
Plot
.
geo
(
prefectures
,
{
fill
:
p
=>
prefectureToPopulation
.
get
(
p
.
properties
.
fullname
)
,
title
:
p
=>
`${
p
.
properties
.
name
} \n ${
prefectureToPopulation
.
get
(
p
.
properties
.
fullname
)
.
toLocaleString
(
)
}`
}
)
]
,
margin
:
20
,
color
:
{
scheme
:
"reds"
,
// Change color scheme
unknown
:
"#ddd"
,
// Polygons with unknown values are gray
type
:
"linear"
,
// Linear scale for color progression
legend
:
true
,
// Add the legend
tickFormat
:
"s"
,
label
:
"Population"
,
// Update legend label
}
}
)
)
Insert cell
Insert cell
populationByCounty
Filter
Columns
5
Sort
Slice
Save
Type Table, then Shift-Enter. Ctrl-space for more options.
Insert cell
addTooltips
(
Plot
.
plot
(
{
projection
:
{
type
:
"albers"
,
rotate
:
[
-
110
,
0
]
,
domain
:
prefectures
}
,
marks
:
[
counties
.
map
(
county
=>
Plot
.
geo
(
county
,
{
fill
:
p
=>
countyToPopulation
.
get
(
p
.
properties
.
fullname
)
,
title
:
p
=>
{
let
name
=
p
.
properties
.
fullname
return
`${
name
} \n ${
countyToPopulation
.
get
(
name
)
.
toLocaleString
(
)
}`
}
}
)
)
,
Plot
.
geo
(
prefectures
)
,
]
,
margin
:
20
,
color
:
{
scheme
:
"reds"
,
// Change color scheme
unknown
:
"#ddd"
,
// Polygons with unknown values are gray
type
:
"linear"
,
// Linear scale for color progression
legend
:
true
,
// Add the legend
tickFormat
:
"s"
,
label
:
"Population"
,
// Update legend label
}
}
)
)
Insert cell
Insert cell
Insert cell
Insert cell
import
{
addTooltips
}
from
"@mkfreeman/plot-tooltip"
Insert cell
import
{
PieChart
}
from
"@d3/pie-chart"
Insert cell
workbook
=
FileAttachment
(
"人口普查.xlsx"
)
.
xlsx
(
)
Insert cell
populationByPrefecture
=
workbook
.
sheet
(
"地级"
,
{
headers
:
true
}
)
Insert cell
genders
=
[
"男"
,
"女"
]
Insert cell
populationByPrefectureGender
=
genders
.
flatMap
(
gender
=>
populationByPrefecture
.
map
(
d
=>
(
{
district
:
d
.
地区
,
gender
,
population
:
d
[
gender
]
}
)
)
)
Insert cell
prefectureToPopulation
=
new
Map
(
populationByPrefecture
.
map
(
(
{
地区
,
男
,
女
}
)
=>
[
地区
,
男
+
女
]
)
)
Insert cell
populationByCounty
=
workbook
.
sheet
(
"县级"
,
{
headers
:
true
}
)
Insert cell
countyToPopulation
=
new
Map
(
populationByCounty
.
map
(
(
{
地区
,
男
,
女
}
)
=>
[
地区
,
男
+
女
]
)
)
Insert cell
innerMongolia
=
d3
.
json
(
"https://geojson.cn/api/data/150000.topo.json"
)
Insert cell
prefectures
=
topojson
.
feature
(
innerMongolia
,
innerMongolia
.
objects
.
default
)
Insert cell
呼和浩特
=
FileAttachment
(
"150100.topo.json"
)
.
json
(
)
Insert cell
包头
=
FileAttachment
(
"150200.topo.json"
)
.
json
(
)
Insert cell
乌海
=
FileAttachment
(
"150300.topo.json"
)
.
json
(
)
Insert cell
赤峰
=
FileAttachment
(
"150400.topo.json"
)
.
json
(
)
Insert cell
通辽
=
FileAttachment
(
"150500.topo.json"
)
.
json
(
)
Insert cell
鄂尔多斯
=
FileAttachment
(
"150600.topo.json"
)
.
json
(
)
Insert cell
呼伦贝尔
=
FileAttachment
(
"150700.topo.json"
)
.
json
(
)
Insert cell
巴彦淖尔
=
FileAttachment
(
"150800.topo.json"
)
.
json
(
)
Insert cell
乌兰察布
=
FileAttachment
(
"150900.topo.json"
)
.
json
(
)
Insert cell
兴安
=
FileAttachment
(
"152200.topo.json"
)
.
json
(
)
Insert cell
锡林郭勒
=
FileAttachment
(
"152500.topo.json"
)
.
json
(
)
Insert cell
阿拉善
=
FileAttachment
(
"152900.topo.json"
)
.
json
(
)
Insert cell
counties
=
[
呼和浩特
,
包头
,
乌海
,
赤峰
,
通辽
,
鄂尔多斯
,
呼伦贝尔
,
巴彦淖尔
,
乌兰察布
,
兴安
,
锡林郭勒
,
阿拉善
]
.
map
(
prefecture
=>
topojson
.
feature
(
prefecture
,
prefecture
.
objects
.
default
)
)
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
Edit
Add comment
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
populationByPrefecture
File attachments
150500.topo.json
JSON
150900.topo.json
JSON
150100.topo.json
JSON
150600.topo.json
JSON
150700.topo.json
JSON
150400.topo.json
JSON
150300.topo.json
JSON
152900.topo.json
JSON
150200.topo.json
JSON
152200.topo.json
JSON
150800.topo.json
JSON
152500.topo.json
JSON
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
chart
Add comment
Copy import
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
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
Cells
populationByCounty
File attachments
150500.topo.json
JSON
150900.topo.json
JSON
150100.topo.json
JSON
150600.topo.json
JSON
150700.topo.json
JSON
150400.topo.json
JSON
150300.topo.json
JSON
152900.topo.json
JSON
150200.topo.json
JSON
152200.topo.json
JSON
150800.topo.json
JSON
152500.topo.json
JSON
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
Edit
Add comment
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
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
workbook
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
populationByPrefecture
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
genders
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
populationByPrefectureGender
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
prefectureToPopulation
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
populationByCounty
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
countyToPopulation
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
innerMongolia
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
prefectures
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
呼和浩特
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
包头
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
乌海
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
赤峰
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
通辽
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
鄂尔多斯
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
呼伦贝尔
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
巴彦淖尔
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
乌兰察布
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
兴安
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
锡林郭勒
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
阿拉善
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
counties
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML