Cannot read property 'scales' of undefined
该报错在 antv f2 绘制柱状图文本是产生
原因: 在图表渲染之前绘制
解决:在 chart.render();
之后绘制
// ....
chart.render();
// 绘制柱状图文本
const offset = -5;
const canvas = chart.get("canvas");
const group = canvas.addGroup();
const shapes = {};
data.forEach(function(obj) {
const point = chart.getPosition(obj);
const text = group.addShape("text", {
attrs: {
x: point.x,
y: point.y + offset,
text: obj.confirmedCount,
textAlign: "center",
textBaseline: "bottom",
fill: "#808080"
}
});
shapes[obj.year] = text; // 缓存该 shape, 便于后续查找
});