AmChart 引用属性 'chart' 在打印引用对象时不为空,但在尝试访问 state.chart 时 'chart' 属性变为空?

AmChart reference attribute 'chart' not null when printing reference object but when trying to access state.chart the 'chart' attribute becomes null?

我是这样引用 AmChart 的:

ref={(e) => {if (e) {this.ch = e}}}

当我在 componentDidMount 中打印 this.ch 时,我可以看到属性 state 存在并且 chart 属性不为空。但是,当我尝试访问 this.ch.state.chart 时,它为空。当我在打印 this.ch 的前一个控制台日志之后立即打印 this.ch.state 时,chart 属性为空。为什么这个属性只有在我尝试访问它时才为空,而在我打印 this.ch?

时却没有

编辑:

无论上述方法是否是访问 chart 的正确方法,您都可以改用 AmCharts 上的事件侦听器来访问图表并进行更改。在AmChart元素标签中的'options'下,添加一个监听器:

   "listeners": [{
            "event": "rendered",
            "method": (e)=>{e.chart.doSomething()};
            }
    }]