針對(duì)Error: Component series. not exists. Load it first的錯(cuò)誤
查到了三中解決辦法,整理一下。
1.設(shè)置series的時(shí)候確保name,data,type這3個(gè)必須的屬性設(shè)置上了.
series: [{
name:'得到',
type:'line',
data:[100.,311.3,322.8,]
}],
2.因?yàn)槌跏蓟痮ption中的series屬性并沒有與myCharts.setOption中的series屬性一一對(duì)應(yīng),因此導(dǎo)致series并未被完全加載
1 function fetchData(cb){
2 setTimeout(function(){
3 cb({
4 categories:["襯衫","羊毛衫","雪紡衫","褲子","高跟鞋","襪子","新增"],
5 data:[5,20,36,10,10,20,60]
6 });
7 },1000);
8 }
9 // 初始化option
10 option={
11 title:{
12 text:'異步數(shù)據(jù)加載'
13 },
14 tooltip:{},
15 legend:{
16 data:['銷量']
17 },
18 xAxis:{
19 data:[]
20 },
21 yAxis:{},
22 series:[{
23 name:'銷量',
24 type:'bar',
25 data:[]
26 }]
27 }
28 fetchData(function(data){
29 mychart.setOption({
30 xAxis:{
31 data:data.categories
32 },
33 yAxis:{},
34 series:[{
35 name:'銷量',
36 type:'bar',
37 data:data.data
38 }]
39 });
40 });
3.vue中的引入方式導(dǎo)致的結(jié)果(我最后解決的辦法)
錯(cuò)誤: main.js中
import echarts from 'echarts/lib/echarts'
改為:
import echarts from 'echarts'