我以这种方式使用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
您认为出了什么问题?我找不到有关此错误的文档...
我有如下所示的导入echarts,它有效
import * as echarts from 'echarts/dist/echarts.js';
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'
此CDN对我有用。将脚本放在HTML文件中。
<script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/4.1.0/echarts-en.common.min.js"></script>
这对我有用(echarts 4.2.1):import * as echarts from 'echarts';