Platform
Resources
Pricing
Sign in
Get started
crazyorr
Workspace
Fork
Public
By
crazyorr
Edited
May 26, 2023
17
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
(
{
y
:
{
grid
:
true
,
tickFormat
:
"s"
}
,
color
:
{
scheme
:
"spectral"
,
domain
:
genders
,
legend
:
true
}
,
marks
:
[
Plot
.
barY
(
populationByPrefectureGender
,
{
x
:
"district"
,
y
:
"population"
,
fill
:
"gender"
,
title
:
"population"
,
sort
:
{
x
:
"y"
,
reverse
:
true
}
}
)
,
Plot
.
ruleY
(
[
0
]
)
]
}
)
)
Insert cell
chart
=
PieChart
(
populationByPrefecture
,
{
name
:
d
=>
d
[
"地区"
]
,
value
:
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
addTooltips
(
Plot
.
plot
(
{
y
:
{
grid
:
true
,
tickFormat
:
d
=>
d
+
1
,
label
:
"↑ Male/Female Ratio"
}
,
color
:
{
scheme
:
"PiYg"
}
,
marks
:
[
Plot
.
barY
(
populationByPrefecture
,
{
x
:
"地区"
,
y
:
d
=>
d
[
"性别比"
]
-
1
,
fill
:
d
=>
Math
.
sign
(
d
[
"性别比"
]
-
1
)
,
title
:
"性别比"
,
sort
:
{
x
:
"y"
,
reverse
:
true
}
,
}
)
,
Plot
.
ruleY
(
[
0
]
)
]
}
)
)
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
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
(
d
=>
[
d
.
地区
,
d
.
合计
]
)
)
Insert cell
shandong
=
d3
.
json
(
"https://geojson.cn/api/data/370000.topo.json"
)
Insert cell
prefectures
=
topojson
.
feature
(
shandong
,
shandong
.
objects
.
default
)
Insert cell
济南
=
FileAttachment
(
"370100.topo.json"
)
.
json
(
)
Insert cell
青岛
=
FileAttachment
(
"370200.topo.json"
)
.
json
(
)
Insert cell
淄博
=
FileAttachment
(
"370300.topo.json"
)
.
json
(
)
Insert cell
枣庄
=
FileAttachment
(
"370400.topo.json"
)
.
json
(
)
Insert cell
东营
=
FileAttachment
(
"370500.topo.json"
)
.
json
(
)
Insert cell
烟台
=
FileAttachment
(
"370600.topo.json"
)
.
json
(
)
Insert cell
潍坊
=
FileAttachment
(
"370700.topo.json"
)
.
json
(
)
Insert cell
济宁
=
FileAttachment
(
"370800.topo.json"
)
.
json
(
)
Insert cell
泰安
=
FileAttachment
(
"370900.topo.json"
)
.
json
(
)
Insert cell
威海
=
FileAttachment
(
"371000.topo.json"
)
.
json
(
)
Insert cell
日照
=
FileAttachment
(
"371100.topo.json"
)
.
json
(
)
Insert cell
临沂
=
FileAttachment
(
"371300.topo.json"
)
.
json
(
)
Insert cell
德州
=
FileAttachment
(
"371400.topo.json"
)
.
json
(
)
Insert cell
聊城
=
FileAttachment
(
"371500.topo.json"
)
.
json
(
)
Insert cell
滨州
=
FileAttachment
(
"371600.topo.json"
)
.
json
(
)
Insert cell
菏泽
=
FileAttachment
(
"371700.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
370500.topo.json
JSON
370600.topo.json
JSON
371100.topo.json
JSON
370400.topo.json
JSON
371500.topo.json
JSON
371300.topo.json
JSON
371000.topo.json
JSON
370300.topo.json
JSON
370800.topo.json
JSON
371600.topo.json
JSON
370900.topo.json
JSON
370200.topo.json
JSON
371400.topo.json
JSON
370100.topo.json
JSON
370700.topo.json
JSON
371700.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
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
370500.topo.json
JSON
370600.topo.json
JSON
371100.topo.json
JSON
370400.topo.json
JSON
371500.topo.json
JSON
371300.topo.json
JSON
371000.topo.json
JSON
370300.topo.json
JSON
370800.topo.json
JSON
371600.topo.json
JSON
370900.topo.json
JSON
370200.topo.json
JSON
371400.topo.json
JSON
370100.topo.json
JSON
370700.topo.json
JSON
371700.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
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
shandong
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
德州
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