在react中使用highcharts-react-official模块呈现棒棒糖图时看到以下错误。如果我将系列类型更改为line
,则渲染效果良好ReferenceError: Highcharts is not defined
示例代码:
import Highcharts, {Options} from 'highcharts'
import HighchartsReact from 'highcharts-react-official'
const options: Options = {
chart: {
type: 'lollipop'
},
series: [{
name: 'Example Series',
type: 'lollipop',
data: [10, 20, 50, 30, 100]
}]
}
const ExampleComponent = () => (
<HighchartsReact
highcharts={Highcharts}
options={options}
/>
)
2条答案
按热度按时间6tqwzwtp1#
请记住正确加载必要的模块:https://github.com/highcharts/highcharts-react#how-to-add-a-module
你可以在这里找到一个简单的演示:https://stackblitz.com/edit/react-hnwmgd?file=index.js
tuwxkamq2#
如果你使用的是Typescript,初始化应该直接在React组件中完成。
如果在组件外部初始化模块,则更新应用后可能会遇到TypeError。