Public
Edited
Oct 19, 2023
1 fork
Insert cell
Insert cell
Insert cell
g2({
type: "view",
width: 1000,
...(country !== "哈马斯" && { scale: { y: { nice: true } } }),
axis: { y: { title: "伤亡人数" }, x: { title: "日期" } },
legend: {
color: {
labelFormatter: (d) => {
const labelByValue = {
israelDeath: "以色列死亡人数",
hamasDeath: "哈马斯死亡人数",
israeInjured: "以色列受伤人数",
hamasInjured: "哈马斯受伤人数"
};
return labelByValue[d];
}
}
},
children: [
{
type: "interval",
data: {
value: data,
transform: [
{
type: "fold",
fields:
country === "全部"
? ["israelDeath", "hamasDeath", "israeInjured", "hamasInjured"]
: country === "以色列"
? ["israelDeath", "israeInjured"]
: ["hamasDeath", "hamasInjured"],
key: "type",
value: "value"
}
]
},
encode: {
x: "date",
y: "value",
color: "type"
},
transform: [{ type: "dodgeX" }]
},
{
type: "line",
data,
encode: {
x: "date",
y: (d) =>
country === "全部"
? d.hamasDeath + d.hamasInjured + d.israelDeath + d.israeInjured
: country === "以色列"
? d.israelDeath + d.israeInjured
: d.hamasDeath + d.hamasInjured
},
style: { stroke: "black" },
tooltip: false
}
]
})
Insert cell
Insert cell
G2 = require("@antv/g2/dist/g2.min.js")
Insert cell
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