VUE2.0+Element-UI+Echarts封装的组件实例
本文用Vue2.0+elementUI的panel组件和table组件+echarts的柱状图和折线图实现对结果的展示,实现了表格和图之间的切换和图和表之间的转置。
-html
{{item.indicatorName}}
本文用Vue2.0+elementUI的panel组件和table组件+echarts的柱状图和折线图实现对结果的展示,实现了表格和图之间的切换和图和表之间的转置。
-html
{{item.indicatorName}}
js,panel组件的代码
varpanelsVue=newVue({
el:"#panels",
props:["initData","indicators","mapOptions"],
data:{
rowOrColumn:false,//行列转换
tableOrMap:true,//表和图切换
tableAndMap:3,//表和图同时显示
mapInitOption:{
title:{
text:''
},
tooltip:{
trigger:'axis'
},
toolbox:{
show:true,
feature:{
mark:{show:true},
dataView:{show:true,readOnly:false},
magicType:{show:true,type:['line','bar']},
restore:{show:true},
saveAsImage:{show:true}
}
},
calculable:true,
xAxis:[
{
type:'category',
boundaryGap:false
}
],
yAxis:[
{
type:'value',
axisLabel:{
formatter:'{value}'
}
}
]
}//echarts初始化参数
},
methods:{
table:function(ev){
if(this.rowOrColumn){
this.indicators=this.listToRowObject(this.initData);
this.mapOptions=this.listToColumnMap(this.initData);
this.rowOrColumn=false;
}else{
this.indicators=this.listToColumnObject(this.initData);
this.mapOptions=this.listToRowMap(this.initData);
this.rowOrColumn=true;
}
for(vari=0;i
在使用上述组件过程中,发现当转置和表格切换之后里面全部都有变化,虽然可以做到单个panel组件自己实现转置和切换,但是发现如果数据太多会导致页面卡死,为了性能优化所以后来考虑采用多vue对象的形式(虽然我的思路是如果改变数据之后,vue将重新渲染html,导致页面卡死,但是后来仔细查资料之后,发现vue当数据改变之后会复用原来相同的html。但是由于时间的原因,也没试。大家可以考虑一下)
采用多vue对象的形式之后的页面
html
js,panel组件
varpanelsVueArr=[];
varresponseData;
functioncreateHtml(respData){
varindicatorResult=respData.indicatorResult;
varindicators=[];
for(varj=0;j上述代码实现了echart图数据的格式化,和对数据的自适应。修改为上述方式之后发现性能提高了不止一个数量级。
以上这篇VUE2.0+Element-UI+Echarts封装的组件实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。