eCharts导入不起作用。未定义_DEV__失败

问题描述 投票:1回答:4

我以这种方式使用NPM,echarts库安装

npm install echarts --save

跟随我在代码中写的documentation

import * as echarts from 'echarts'

然后我尝试了一个非常简单的示例

const $chart = $('#chart')
let myChart = echarts.init($chart)
const option = {
  title: {
    text: 'ECharts entry example'
  },
  tooltip: {},
  legend: {
    data: ['Sales']
  },
  xAxis: {
    data: ['shirt', 'cardign', 'chiffon shirt', 'pants', 'heels', 'socks']
  },
  yAxis: {},
  series: [
    {
      name: 'Sales',
      type: 'bar',
      data: [5, 20, 36, 10, 10, 20]
    }
  ]
}
myChart.setOption(option)

但我收到此错误

ReferenceError: __DEV__ is not defined

您认为出了什么问题?我找不到有关此错误的文档...

javascript node.js import echarts
4个回答
1
投票

我有如下所示的导入echarts,它有效

import * as echarts from 'echarts/dist/echarts.js';

1
投票
  import * as echarts from 'echarts/lib/echarts'
  import 'echarts/lib/chart/line'
  import 'echarts/lib/chart/bar'
  import 'echarts/lib/component/tooltip'
  import 'echarts/lib/component/title'
  import 'echarts/lib/component/legend'

0
投票

此CDN对我有用。将脚本放在HTML文件中。

<script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/4.1.0/echarts-en.common.min.js"></script>

0
投票

这对我有用(echarts 4.2.1):import * as echarts from 'echarts';

© www.soinside.com 2019 - 2024. All rights reserved.