antvis/G2

使用 chart.options() 声明图表,chart.getScale() 失效 #5182

pearmini posted onGitHub

  • 版本:5.0.12
import { Chart } from "@antv/g2";

const chart = new Chart({ container: "container" });

chart.options({
  type: "interval",
  theme: "classic",
  autoFit: true,
  data: {
    type: "fetch",
    value:
      "https://gw.alipayobjects.com/os/bmw-prod/fb9db6b7-23a5-4c23-bbef-c54a55fee580.csv",
  },
  encode: { x: "letter", y: "frequency" },
  axis: { y: { labelFormatter: ".0%" } },
});

chart.render();

chart.getScale(); //  undefined

chart.render is an async function

chart.render().then(chart => chart.getScale())

Or you can use top level await or use G2 event to get scale after render

Maybe close this issue

posted by tyr1dev almost 2 years ago

That make sense.

posted by pearmini almost 2 years ago

Fund this Issue

$0.00
Funded

Pull requests