apache / echarts

Apache ECharts is a powerful, interactive charting and data visualization library for browser
https://echarts.apache.org
Apache License 2.0
60.43k stars 19.61k forks source link

object is not a constructor #16780

Open reeshuai opened 2 years ago

reeshuai commented 2 years ago

Version

5.3.1

Link to Minimal Reproduction

No response

Steps to Reproduce

  1. we use vue2 and echarts5.3.1.
  2. echarts options:
    option: {
        tooltip: {
          trigger: 'item'
        },
        legend: {
          left: 'center',
          bottom: '2%',
          icon: 'circle',
          itemGap: 10,
          orient: 'horizontal',
          formatter: function (name) {
            const str = name.split(' ')
            return str[0] + ':¥' + str[1]
          }
        },
        series: [
          {
            top: 'middle',
            left: 'center',
            type: 'pie',
            radius: ['20%', '40%'],
            width: 390,
            height: 390,
            itemStyle: {
              borderRadius: 0,
              borderColor: '#fff',
              borderWidth: 1
            },
            label: {
              show: true,
              color: '#404040',
              fontWeight: 400,
              fontFamily: 'PinFangSC',
              fontSize: 14,
              formatter: (item) => {
                return item.name.split(' ')[0]
              }
            },
            labelLine: {
              show: true,
              length: 15,
              length2: 10
            },
            emphasis: {
              scale: true,
              scaleSize: 10,
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            },
            data: [],
            tooltip: {
              valueFormatter: (item) => {}
            }
          }
        ]
      },

Current Behavior

The following issues occur just on iPhone (ios 14.4),other phones and browsers run without problems

image

Expected Behavior

image

Environment

- OS:iphone ios 14.4
- Browser: safari
- Framework:

Any additional comments?

I guess there is a problem with the compiled code. It should be a compatibility problem after compiling the code, but I don't know how to fix it.

source code: node_modules\echarts\lib\model\Global.js

           // PENDING Global as parent ?
            var extraOpt = extend({
              componentIndex: index
            }, resultItem.keyInfo);
            componentModel = new ComponentModelClass(newCmptOption, this, this, extraOpt); // Assign `keyInfo`

            extend(componentModel, extraOpt);

compiled code:

            var i = g.a.getClass(o, e.keyInfo.subType, !("series" === o));
                        console.log("mainType:", o, "subType:", e.keyInfo.subType, "!isSeriesType:", !("series" === o), "ComponentModelClass:", i);
                        if (!i) return;
                        if ("tooltip" === o) {
                            if (a) return;
                            a = !0
                        }
                        n && n.constructor === i ? (n.name = e.keyInfo.name, n.mergeOption(r, this), n.optionUpdated(r, !1)) : (n = new i(r, this, this, i = Object(h.m)({
                            componentIndex: t
                        },
                        e.keyInfo)), Object(h.m)(n, i), e.brandNew && (n.__requireNewView = !0), n.init(r, this, this), n.optionUpdated(null, !0))

there may be incompatible code: 

       (n = new i(r, this, this, i = Object(h.m)({componentIndex: t},e.keyInfo))
MGYYM commented 2 years ago

I have same problem use vue2 and echarts5.3.2 OS:iphone ios 12.0.1

liuhq8796 commented 2 years ago

我使用的是 Vue3 和 GaugeChart 图表,设备有 iPhone8 13.5.1、iPhone XR 14.4.1、iPhone 13 Pro Max 15.4.1

经过测试发现,在不同ios版本、echarts版本、echarts引入方式的情况下表现均有不同:

echarts 版本5.3.2 全局引入和按需引入:ios13 和 ios 14 报错,ios15 正常 echarts 版本5.2.2 以及 5.0.2 全局引入:全部正常 echarts 版本5.2.2 以及 5.0.2 按需引入:ios13 和 ios 14 报错,ios15 正常

RybinLi commented 2 years ago

我最近也碰到了同样的问题, echarts 版本5.1.1 按需引入:ios13 和 ios 14 报错,ios15 正常

RybinLi commented 2 years ago

我最近也碰到了同样的问题, echarts 版本5.1.1 按需引入:ios13 和 ios 14 报错,ios15 正常

今天找到解决办法了,不过只适用于使用webpack 4版本的。 问题原因:是因为vue.config.js里配置的是低版本的TerserPlugin插件,并且使用 paralleUglifyPlugin 进行压缩打包,而根据terser github文档里的描述,uglify是不支持ES6+的,所以大家可以排查下自己的项目打包是不是使用了uglify。

uglify-js does not support ES6+.

解决方法: 对于webpack 4的,将TerserPlugin升级到对应版本(4.x.x),去除uglify打包,根据这里的指引配置TerserPlugin

目前我这样操作后,问题就解决了。

mori-yong commented 7 months ago

这个问题解决了吗?5.4的版本ios也出现了这个问题