我想在我的 React 应用程序中使用 amcharts5 创建图表。
我在我的应用程序组件中导入的组件中实例化 amcharts5 的根元素。我收到以下错误
You cannot have multiple Roots in the same DOM node
Run Code Online (Sandbox Code Playgroud)
这是我的版本:
"react": "^17.0.2"
"@amcharts/amcharts5": "^5.1.1"
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
import { useLayoutEffect } from 'react'
import * as am5 from '@amcharts/amcharts5'
export default function AmCharts5() {
useLayoutEffect(() => {
let root = am5.Root.new('chartdiv')
// root.current = root
// here is a second Error : Property 'current' does not exist on type 'Root'
return () => {
root.dispose()
}
}, [])
return <div id="chartdiv" style={{ width: …Run Code Online (Sandbox Code Playgroud)