Skip to content
大纲

分面

分面指对数据按照某个维度分隔成若干子集,然后创建一个图表的矩阵,将每个数据子集绘制到图表矩阵的窗格中。

分面类型说明
rect默认类型,指定 2 个维度作为行列,形成图表的矩阵。
list指定一个维度,可以指定一行有几列,超出自动换行。
circle指定一个维度,沿着圆分布。
tree指定多个维度,每个维度作为树的一级,展开多层图表。
mirror指定一个维度,形成镜像图表。
matrix指定一个维度,形成矩阵分面。

使用分面: chart.facet(type: string, cfg: FacetCfg) => View

应用示例

ts
import { Chart } from "@antv/g2";
const chart = new Chart({
  container: "chart",
  width: 800,
  height: 500,
});
const data = [
  { type: "a", x: 0, y: 0 },
  { type: "a", x: 1, y: 1 },
  { type: "b", x: 0, y: 1 },
  { type: "b", x: 1, y: 0 },
];
chart.data(data);
chart.facet("rect", {
  fields: ["type"],
  eachView(view, facet) {
    view.line().position("x*y").color("type");
  },
});
chart.render();