0

我在 React 中使用 highcharts,我想调用 .get() 方法。官方演示是这样的:

var chart = $('#container').highcharts(),
    locationA = chart.get('locationA'),
    locationB = chart.get('locationB'),
    locationC = chart.get('locationC'),
    locationD = chart.get('locationD');

我想在 React 中聊天,所以我也使用 highcharts-react lib,我创建了一个这样的 ref:

constructor(props) {
        super(props);
        this.chartComponent = React.createRef();
    }

render() {
        console.dir(usaBubbleData);
        return (
            <div className='container'>
                <HighchartsReact
                    highcharts={Highcharts}
                    constructorType={"mapChart"}
                    options={maplineOptions}
                    ref={this.chartComponent}
                />
            </div>
        );
    }

componentDidMount() {
        var locationA = this.chartComponent.get("locationA"),
}

我得到一个错误: × TypeError: this.chartComponent.get is not a function

我不知道 React 中的 ref 和 ref 是同一个实例var chart = $('.container').highcharts()吗?

谁能告诉我有什么问题?

4

1 回答 1

0

更新:我自己解决了这个问题。

事实上图表实例不是 this.chartComponent ,它是this.chartComponent.current.char

于 2019-05-08T05:52:29.053 回答