首页 > 解决方案 > “未通过“highcharts”属性”constructorType="chart" 警告

问题描述

我正在开始一个项目,我想将 Highchart stockChartreact 组件改编为常规 Highchart ( chart) 组件。我在演示中对其进行了调整,一切正常。

当我移动到我的本地项目时,我无法constructorTypestockChartto更改chart,它可以编译但是当我尝试运行应用程序时出现此错误

类型错误:t[n] 不是函数

C:/src/HighchartsReact.js:30


  27 | const H = props.highcharts || Highcharts;
  28 | const constructorType = props.constructorType || 'chart';
  29 | 
> 30 | if (!H) {
     | ^  31 |   console.warn('The "highcharts" property was not passed.');
  32 | 
  33 | } else if (!H[constructorType]) {

(匿名函数)

C:/src/HighchartsReact.js:52

  49 | }
  50 | 
  51 | if (!chartRef.current) {
> 52 |   createChart();
     | ^  53 | } else {
  54 |   if (props.allowChartUpdate !== false) {
  55 |     if (!props.immutable && chartRef.current) {

我的本地项目运行与演示相同的依赖项,我不知道我为什么要面对这个TypeError。根据文档,这是默认调用。

标签: javascriptreactjshighchartsreact-highcharts

解决方案


我遇到了这个问题,因为您必须专门将主要的 Highcharts 对象传递给 HighchartsReact,如下所示:

import Highcharts from "highcharts";

return (
        <HighchartsReact
            highcharts={Highcharts}
            options={hiChartsOptions}
        />
    );


推荐阅读