Published
Edited
May 11, 2022
1 star
Insert cell
Insert cell
## aggregate
Insert cell
result2 = {
const data = [
{ Day: 1, Value: 54.8 },
{ Day: 2, Value: 112.1 },
{ Day: 3, Value: 63.6 },
{ Day: 4, Value: 37.6 },
{ Day: 5, Value: 79.7 },
{ Day: 6, Value: 137.9 },
{ Day: 7, Value: 120.1 },
{ Day: 8, Value: 103.3 },
{ Day: 9, Value: 394.8 },
{ Day: 10, Value: 199.5 },
{ Day: 11, Value: 72.3 },
{ Day: 12, Value: 51.1 },
{ Day: 13, Value: 112.0 },
{ Day: 14, Value: 174.5 },
{ Day: 15, Value: 130.5 }
];
const dv = new DataSet.DataView().source(data);
dv.transform({
type: "aggregate", // 别名summary
fields: ["Value"], // 统计字段集
operations: ["mean"], // 统计操作集
as: ["mean"] // 存储字段集
// groupBy: ["Value"] // 分组字段集
});
return dv.rows;
}
Insert cell
result = {
const dv = new DataSet.DataView().source(data);
dv.transform({
type: "partition",
groupBy: ["name"], // 以 name 字段进行分组
orderBy: ["value"] // 以 value 字段进行排序
});
return dv.rows;
}
Insert cell
data = [
{ name: "a", value: 2 },
{ name: "c", value: 2 },
{ name: "b", value: 3 },
{ name: "b", value: 1 },
{ name: "a", value: 1 },
{ name: "b", value: -1 }
]
Insert cell
DataSet = require("@antv/data-set")
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