Public
Edited
Jan 3, 2023
Paused
pie-chart
Scatterplot(散点图)
Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
marks: [Plot.dot(cars, { x: "power (hp)", y: "economy (mpg)" })]
})
Insert cell
cars
Insert cell
Insert cell
Insert cell
import { nycSpreadsheet } from "@observablehq/build-your-first-custom-scatterplot"
Insert cell
// 读取sheet数据并且保留表格的header
nycData = nycSpreadsheet.sheet(0, { headers: true })
Insert cell
//同样绘制一个scatterplot
Plot.plot({
marks: [Plot.dot(nycData, { x: "date", y: "medianAskingPrice" })]
})
Insert cell
Insert cell
//让某一列值作为填充值
Plot.plot({
marks: [
Plot.dot(nycData, {
x: "date",
y: "medianAskingPrice",
fill: "neighborhood", //散点填充
r: "priceCutShare" //散点大小
})
],
color: { legend: true }, //添加图例信息
marginLeft: 100
})
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.ruleY([0]),
Plot.line(nycData, {
x: "date",
y: "medianAskingPrice",
stroke: "neighborhood" //线条不闭合
}),
Plot.dot(nycData, {
x: "date",
y: "medianAskingPrice",
fill: "neighborhood",
r: "priceCutShare"
})
],
color: { legend: true },
marginLeft: 100
})
Insert cell
Insert cell
chart = Plot.plot({
facet: {
data: nycData,
y: "borough",
marginRight: 100
},
marks: [
Plot.ruleY([0]),
Plot.line(nycData, {
x: "date",
y: "medianAskingPrice",
stroke: "neighborhood" //线条不闭合
}),
Plot.dot(nycData, {
x: "date",
y: "medianAskingPrice",
fill: "neighborhood",
r: "priceCutShare"
})
],
color: { legend: true },
marginLeft: 100
})
Insert cell
Insert cell
ExportPicture({
DOM: DOM,
chart: chart,
filename: "scatterplot",
fileType: "svg"
})
Insert cell
Insert cell
import { ExportPicture } from "@zpliu1126/core"
Insert cell
import { toc } from "@nebrius/indented-toc"
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more