报错:`TypeError: Cannot use 'in' operator to search for '_ec_inner'
at ExtendedClass.setOption (Global.js?6023:119)
at ECharts.echartsProto.setOption (echarts.js?deac:385)
是数据没拿到之前就渲染的问题吗? 要怎么改 求助
前端
mounted(){
this.$store.dispatch('getThemeData');
this.init();
},
computed:{
...mapGetters(['themeData'])
},
methods:{
init(){
let option={
title : {
text: 'Theme of postings',
x:'center',
textStyle:{
color:'#ccc',
//字体风格,'normal','italic','oblique'
fontStyle:'normal',
//字体粗细 'normal','bold','bolder','lighter',100 | 200 | 300 | 400...
fontWeight:'bold',
//字体系列
fontFamily:'sans-serif',
//字体大小
fontSize:30
}
},
tooltip : {
trigger: 'item',
formatter: "{a} <br/>{b} : {c} ({d}%)"
},
legend: {
textStyle:{
//字体风格,'normal','italic','oblique'
fontStyle:'normal',
//字体粗细 'normal','bold','bolder','lighter',100 | 200 | 300 | 400...
fontWeight:'normal',
//字体系列
fontFamily:'sans-serif',
//字体大小
fontSize:14
},
orient: 'vertical',
left: 'left',
top:'10%',
data:['Disclosure of air pollution',
'Dissatisfaction with the poor air quality',
'Report of behavioral changes',
'Health concern for his or her health',
'Banter about the poor air quality','Evaluation of government policy',
'Appeal to the government to reduce air pollution']
},
toolbox: {
text:'dsdd',
show : true,
feature : {
mark : {show: true},
magicType : {
show: true,
type: ['pie', 'funnel']
},
restore : {show: true},
saveAsImage : {show: true}
}
},
calculable : true,
series : [
{
name:'Theme of Postings',
type:'pie',
radius : [30, 110],
center : ['50%', '60%'],
roseType : 'area',
data:this.themeData
}
]
}
this.myChart = this.$echarts.init(document.querySelector('.theme .main'));
this.myChart.setOption(this.option)
}
},
vuex管理数据
const getters = {
themeData: (state) => {
return state.theme_data;
},
}
// actions
const actions = {
getThemeData:(context)=>{
axios.get('static/theme.json').then((res)=>{
return res.data.data;
}).then((data)=>{
context.commit('setThemeData',data);
})
}
}
// mutations
const mutations = {
setThemeData:(state,data)=>{
var temp=[];
for(var i=0;i<data.length;i++){
console.log(data[i])
let t={
value:data[i].percent,
name:data[i].theme
}
temp.push(t);
}
state.theme_data=temp;
}
watch有值再进行渲染