<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當(dāng)前位置: 首頁 - 科技 - 知識(shí)百科 - 正文

        VUE2.0+Element-UI+Echarts封裝的組件實(shí)例

        來源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-27 22:18:23
        文檔

        VUE2.0+Element-UI+Echarts封裝的組件實(shí)例

        VUE2.0+Element-UI+Echarts封裝的組件實(shí)例:本文用Vue2.0+elementUI的panel組件和table組件+echarts的柱狀圖和折線圖實(shí)現(xiàn)對結(jié)果的展示,實(shí)現(xiàn)了表格和圖之間的切換和圖和表之間的轉(zhuǎn)置。 -html <div class=resultDiv> <div id=panels> <el-colla
        推薦度:
        導(dǎo)讀VUE2.0+Element-UI+Echarts封裝的組件實(shí)例:本文用Vue2.0+elementUI的panel組件和table組件+echarts的柱狀圖和折線圖實(shí)現(xiàn)對結(jié)果的展示,實(shí)現(xiàn)了表格和圖之間的切換和圖和表之間的轉(zhuǎn)置。 -html <div class=resultDiv> <div id=panels> <el-colla

        本文用Vue2.0+elementUI的panel組件和table組件+echarts的柱狀圖和折線圖實(shí)現(xiàn)對結(jié)果的展示,實(shí)現(xiàn)了表格和圖之間的切換和圖和表之間的轉(zhuǎn)置。

        -html

        <div class="resultDiv">
         <div id="panels">
         <el-collapse>
         <el-collapse-item v-for="item in indicators">
         <template slot="title">
         <span class='resulticon'>
         {{item.indicatorName}} 
         <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="el-icon-upload2" :class="item.indicatorName" download="somedata.xls" @click="return exportExcel(item.indicatorName)" 
         data-command="show" title="保存為表"></a>
         <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="glyphicon glyphicon-repeat" aria-hidden="true" @click="convert" data-command="show" title="圖表切換"></a>
         <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="glyphicon glyphicon-transfer" aria-hidden="true" @click="transpose" data-command="show" title="行列轉(zhuǎn)置"></a>
         </span>
         </template>
         <template>
         <div v-show="tableAndMap==3?true:tableAndMap==1?true:false" :id="item.indicatorName"></div>
         </template>
         <template v-if="tableAndMap==3?true:tableAndMap==2?true:false">
         <el-table :data="item.tableData" max-height="300" stripe border fix style="width: 100%">
         <el-table-column v-for="(column,index) in item.columns" :prop="column" :fixed="index==0" :label="column" min-width="150"></el-table-column>
         </el-table>
         </template>
         </el-collapse-item>
         </el-collapse>
         </div> 
         </div>

        js,panel組件的代碼

        var panelsVue = new Vue({
         el : "#panels",
         props : ["initData","indicators","mapOptions"],
         data : {
         rowOrColumn : false, //行列轉(zhuǎn)換
         tableOrMap : true, //表和圖切換
         tableAndMap : 3, //表和圖同時(shí)顯示
         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 初始化參數(shù)
         },
         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(var i=0;i<this.mapOptions.length;i++){
         var indicatorName= this.mapOptions[i].title.text;
         var dom = document.getElementById([indicatorName])
         var heigth = $(dom).siblings('div').height()*1.5;
         var width = $(dom).siblings('div').width();
         $(dom).css({
         height:heigth,
         width:width
         });
         var myChart= echarts.init(document.getElementById([indicatorName]),'macarons');
         myChart.setOption(this.mapOptions[i]);
         }
         ev.stopPropagation();
         },
         listToRowObject :function (ListAndList){
         var indicatorNames=[];
         var tableDatas=[];
         var columns = [];
         var options = [];
         ListAndList = ListAndList.indicatorResult;
         for(var i=0;i<ListAndList.indicatorNames.length;i++){
         var objects=[];
         var column =[];
         var indicatorName = ListAndList.indicatorNames[i];
         for(var yIndex in ListAndList[indicatorName]){
         var obj = {};
         obj[indicatorName]=ListAndList.colKeys[yIndex];
         for(var xIndex in ListAndList[indicatorName][yIndex]){
         obj[ListAndList.rowKeys[xIndex]]=ListAndList[indicatorName][yIndex][xIndex];
         }
         objects.push(obj);
         }
         indicatorNames.push(indicatorName);
         column.push(indicatorName);
         column=column.concat(ListAndList.rowKeys);
         var indicator={};
         indicator[indicatorName]=objects;
         columns.push(column);
         tableDatas.push(indicator);
         }
         for(var j = 0; j<indicatorNames.length;j++){
         var indicatorObj = {};
         indicatorObj["tableData"]=tableDatas[j][indicatorNames[j]];
         indicatorObj["columns"] = columns[j];
         indicatorObj["indicatorName"] = indicatorNames[j];
         options.push(indicatorObj);
         }
         return options;
         },
         listToColumnObject :function (ListAndList) {
         var options = [];
         var columns = [];
         var indicatorNames = [];
         var indicatorMap = {};
         ListAndList = ListAndList.indicatorResult;
         for (var i = 0; i < ListAndList.indicatorNames.length; i++) {
         var column = [];
         var objs = [];
         var indicatorName = ListAndList.indicatorNames[i];
         indicatorNames.push(indicatorName);
         column.push(indicatorName);
         column = column.concat(ListAndList.colKeys);
         columns.push(column);
         var indicatorData = [];
         indicatorData.push(ListAndList.rowKeys);
         indicatorData = indicatorData.concat(ListAndList[indicatorName]);
         for (var k = 0; k < indicatorData[0].length; k++) {
         var aRow = {};
         for (var j = 0; j < indicatorData.length; j++) {
         aRow[column[j]] = indicatorData[j][k];
         }
         objs.push(aRow);
         }
         indicatorMap[indicatorName] = objs;
         }
         for (var j = 0; j < indicatorNames.length; j++) {
         var indicatorObj = {};
         indicatorObj["tableData"] = indicatorMap[indicatorNames[j]];
         indicatorObj["columns"] = columns[j];
         indicatorObj["indicatorName"] = indicatorNames[j];
         options.push(indicatorObj);
         }
         return options;
         },
         listToColumnMap: function(ListAndList){
         ListAndList = ListAndList.indicatorResult;
         var options=[];
         for(var j = 0;j<ListAndList.indicatorNames.length;j++){
         var sigleOption ={};
         sigleOption=JSON.parse(JSON.stringify(this.mapInitOption));//實(shí)現(xiàn)深復(fù)制
         sigleOption.xAxis[0]["data"]=ListAndList.rowKeys;
         var indicatorName = ListAndList.indicatorNames[j];
         sigleOption["title"]["text"]=indicatorName;
         var series =[];
         for(var k=0;k<ListAndList[indicatorName].length;k++){
         var sigleSerie={type:'line'};
         sigleSerie["name"] = ListAndList.colKeys[k];
         sigleSerie["data"] = ListAndList[indicatorName][k];
         series.push(sigleSerie);
         }
         sigleOption["series"]=series;
         options.push(sigleOption);
         };
         return options;
         },
         listToRowMap: function(ListAndList){
         ListAndList = ListAndList.indicatorResult;
         var options=[];
         for(var j = 0;j<ListAndList.indicatorNames.length;j++){
         var sigleOption ={};
         sigleOption=JSON.parse(JSON.stringify(this.mapInitOption));//實(shí)現(xiàn)深復(fù)制
         sigleOption.xAxis[0]["data"]=ListAndList.colKeys;
         var indicatorName = ListAndList.indicatorNames[j];
         sigleOption["title"]["text"]=indicatorName;
         var series =[];
         for(var k=0;k<ListAndList.rowKeys.length;k++){
         var sigleSerie={type:'line'};
         var x= [];
         for(var z = 0;z<ListAndList.colKeys.length;z++){
         x.push(ListAndList[indicatorName][z][k]);
         }
         sigleSerie["name"] = ListAndList.rowKeys[k];
         sigleSerie["data"] = x;
         series.push(sigleSerie);
         }
         sigleOption["series"]=series;
         options.push(sigleOption);
         };
         return options;
         },
         map : function(ev){
         if(this.tableAndMap==1){
         this.tableAndMap=2;
         }else if(this.tableAndMap==2){
         this.tableAndMap=3;
         }else{
         this.tableAndMap=1;
         }
         ev.stopPropagation();
         },
         exportExcel : function(indicatorName,my){
         debugger;
         console.log(indicatorName);
         var listAndList = JSON.parse(JSON.stringify(this.initData.indicatorResult));
         var rowTd = listAndList.rowKeys;
         var excellData=[];
         rowTd.splice(0,0,indicatorName);
         excellData.push(rowTd);
         for(var i = 0;i<listAndList[indicatorName].length;i++){
         var rowTr = listAndList[indicatorName][i];
         rowTr.splice(0,0,listAndList.colKeys[i]);
         excellData.push(rowTr);
         }
         return ExcellentExport.excelByData($("."+indicatorName)[0], excellData, 'Sheet', 'download' + new Date().getTime() + '.xls');
         }
         },
         watch : {
         initData : function(newValue){
         this.indicators=this.listToRowObject(newValue);
         }
         },
         mounted : function(){
         }
        });
        Vue.set(panelsVue,'initData',ListAndList);

        在使用上述組件過程中,發(fā)現(xiàn)當(dāng)轉(zhuǎn)置和表格切換之后里面全部都有變化,雖然可以做到單個(gè)panel組件自己實(shí)現(xiàn)轉(zhuǎn)置和切換,但是發(fā)現(xiàn)如果數(shù)據(jù)太多會(huì)導(dǎo)致頁面卡死,為了性能優(yōu)化所以后來考慮采用多vue對象的形式(雖然我的思路是如果改變數(shù)據(jù)之后,vue將重新渲染html,導(dǎo)致頁面卡死,但是后來仔細(xì)查資料之后,發(fā)現(xiàn)vue當(dāng)數(shù)據(jù)改變之后會(huì)復(fù)用原來相同的html。但是由于時(shí)間的原因,也沒試。大家可以考慮一下)

        采用多vue對象的形式之后的頁面

        html

        <div class="resultDiv"></div>

        js,panel組件

        var panelsVueArr = [];
        var responseData;
        function createHtml(respData){
         var indicatorResult = respData.indicatorResult; 
         var indicators = [];
         for(var j=0;j<indicatorResult.indicatorNames.length;j++){
         var indicator = {};
         indicator["indicatorName"]=indicatorResult.indicatorNames[j];
         indicator["indicatorUnit"]=indicatorResult.indicatorUnits[j];
         indicator["rowKeys"]=indicatorResult.rowKeys;
         indicator["colKeys"]=indicatorResult.colKeys;
         indicator["indicatorData"]=indicatorResult[indicatorResult.indicatorNames[j]];
         indicators.push(indicator);
         }
         for(var i =0;i<indicators.length;i++){
         var el = $("<div></div>");
         $(".resultDiv").append(el[0]); 
         var vueObj = new Vue({
         el : el[0],
         template : '<div id="panels"><el-collapse><el-collapse-item>'+
         '<template slot="title"><span class="resulticon">{{item.indicatorName}}({{item.indicatorUnit}}) <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="el-icon-upload2" :class="item.indicatorName" download="somedata.xls" @click="exportExcel" data-command="show" title="保存為表"></a>'+
         '<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="glyphicon glyphicon-repeat" aria-hidden="true" @click="convert" data-command="show" title="圖表切換"></a><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="glyphicon glyphicon-transfer" aria-hidden="true" @click="transpose" data-command="show" title="行列轉(zhuǎn)置"></a>'+
         '</span></template><template><div v-show="!tableAndMap" :id="item.indicatorName"></div></template><template v-if="tableAndMap"><el-table :data="item.tableData" max-height="300" stripe border fix fit style="width: 100%">'+
         '<el-table-column v-for="(column,index) in item.columns" :prop="column" :fixed="index==0" :label="column" :min-width="column.length<8?118:column.length>16?250:column.length*15"></el-table-column></el-table></template></el-collapse-item></el-collapse></div>',
         props : ['item','mapOption'],
         data : {
         indicator : indicators[i],
         rowOrColumn : false, // 行列轉(zhuǎn)換
         tableOrMap : true, // 表和圖切換
         tableAndMap : true, // 表和圖同時(shí)顯示
         indexid : i,
         mapInitOption : {
         title : {
         text : '',
         show : false
         },
         tooltip : {
         trigger : 'item',
         formatter: ''
         },
         legend : {
         data : [],
         right : 90, // 不要遮住右邊的按鈕
         left : 85,
         padding : 10
         },
         toolbox : {
         show : true,
         feature : {
         mark : {
         show : true
         },
         magicType : {
         show : true,
         type : ['line', 'bar']
         },
         restore : {
         show : true
         },
         saveAsImage : {
         show : true
         }
         }
         },
         grid : {
         y : '',
         y2 : '',
         containLabel : true
         },
         calculable : true,
         xAxis : [{
         type : 'category',
         boundaryGap : false,
         axisLabel : {
         interval : 0
         // rotate : 45
         }
         }
         ],
         yAxis : [{
         type : 'value',
         axisLabel : {
         formatter : yAxisFormatter
         }
         }
         ]
         } // echarts 初始化參數(shù)
         },
         methods : {
         transpose : function (ev) {
         if (this.rowOrColumn) {
         this.item = this.listToRowObject(this.indicator);
         this.mapOption = this.listToRowMap(this.indicator);
         this.rowOrColumn = false;
         } else {
         this.item = this.listToColumnObject(this.indicator);
         this.mapOption = this.listToColumnMap(this.indicator);
         this.rowOrColumn = true;
         }
         var indicatorName = this.mapOption.title.text;
         var myChart = echarts.init(document.getElementById([indicatorName]),rmp_theme);
         var grid = computerGrid(this.mapOption);
         myChart.resize({
         width : grid.chartWidth+"px",
         height : grid.chartHeight+"px"
         });
         myChart.setOption(this.mapOption);
         ev.stopPropagation();
         },
         listToColumnObject : function (ListAndList) {
         var x_y = column.text+"\\"+row.text;
         var itemTable ={};
         var columnR = [];
         var tableData=[];
         for (var yIndex in ListAndList.indicatorData) {
         var obj = {};
         obj[x_y] = ListAndList.colKeys[yIndex];
         for (var xIndex in ListAndList.indicatorData[yIndex]) {
         obj[ListAndList.rowKeys[xIndex]] =cellsDeal(ListAndList.indicatorData[yIndex][xIndex],ListAndList.indicatorUnit);
         }
         tableData.push(obj);
         }
         columnR.push(x_y);
         columnR = columnR.concat(ListAndList.rowKeys);
         itemTable["indicatorName"]=ListAndList.indicatorName;
         itemTable["tableData"] = tableData;
         itemTable["columns"]=columnR;
         itemTable["indicatorUnit"]=ListAndList.indicatorUnit;
         return itemTable;
         },
         listToRowObject : function (ListAndList) {
         var itemTable ={};
         var indicatorMap = {};
         var indicatorData=[];
         var y_x = row.text+"\\"+column.text;
         var columnR = [];
         var tableData = [];
         columnR.push(y_x);
         columnR = columnR.concat(ListAndList.colKeys);
         indicatorData.push(ListAndList.rowKeys);
         indicatorData = indicatorData.concat(ListAndList.indicatorData);
         for (var k = 0; k < indicatorData[0].length; k++) {
         var aRow = {};
         for (var j = 0; j < indicatorData.length; j++) {
         if(j==0){
         aRow[columnR[j]] = indicatorData[j][k];
         }else{
         aRow[columnR[j]] = cellsDeal(indicatorData[j][k],ListAndList.indicatorUnit);
         }
         }
         tableData.push(aRow);
         }
         itemTable["indicatorName"]=ListAndList.indicatorName;
         itemTable["tableData"] = tableData;
         itemTable["columns"]=columnR;
         itemTable["indicatorUnit"]=ListAndList.indicatorUnit;
         return itemTable;
         },
         listToColumnMap : function (ListAndList) {
         // var echartOption = echarts.getInstanceByDom(document.getElementById(ListAndList.indicatorName)).getOption();
         // var mapType = echarts.getInstanceByDom(document.getElementById(ListAndList.indicatorName)).getOption().series[0].type;
         var options = [];
         var sigleOption = {};
         sigleOption = this.mapInitOption; // 實(shí)現(xiàn)深復(fù)制
         var rowKeys = JSON.parse(JSON.stringify(ListAndList.rowKeys));
         rowKeys.pop();
         sigleOption.xAxis[0]["data"] = rowKeys;
         var indicatorName = ListAndList.indicatorName;
         sigleOption["title"]["text"] = indicatorName;
         var series = [];
         for (var k = 0; k < ListAndList.indicatorData.length - 1; k++) {
         var sigleSerie = {
         type : 'line',
         barMaxWidth : 40,
         barMinHeight : 15
         };
         sigleSerie["name"] = ListAndList.colKeys[k];
         var rows = JSON.parse(JSON.stringify(ListAndList.indicatorData[k]))
         rows.pop();
         sigleSerie["data"] = rows;
         series.push(sigleSerie);
         }
         sigleOption["series"] = series;
         var legendData = JSON.parse(JSON.stringify(ListAndList.colKeys));
         legendData.pop();
         sigleOption.legend.data = legendData;
         var unitHandle=ListAndList.indicatorUnit;
         sigleOption.tooltip.formatter=function (params,ticket,callback) {
         var myUnit =unitHandle;
         var html = '<span style="display:inline-block;margin-right:5px;"'+
         '>行:'+params.seriesName +'</span><br>';
         html+='<span style="display:inline-block;margin-right:5px;'+
         '">列:'+params.name +'</span><br>';
         var showValue = params.value;
         if (typeof (showValue) == "undefined") {
         showValue = "NoData";
         } else {
         // 圖懸浮框 千分位+萬 +單位
         if (!isNaN(showValue)) {
         if (showValue > 10000) {
         showValue = toThousands((showValue / 10000).toFixed(1)) + $.i18n.get('chart.wan')+ myUnit;
         }else{
         if(unitHandle=='%'){
         showValue=parseFloat(showValue)*100;
         showValue = showValue.toFixed(1) + myUnit;
         }else{
         showValue = showValue.toFixed(1) + myUnit;
         }
         }
         }
         }
         html+='<span style="display:inline-block;margin-right:5px;'+
         '">值:'+showValue +'</span>';
         return html;
         };
         return sigleOption;
         },
         listToRowMap : function (ListAndList) {
         /* var mapType;
         if(typeof(this.mapOptions)=='undefined'){
         mapType='line';
         }else{
         mapType = echarts.getInstanceByDom(document.getElementById(ListAndList.indicatorNames[0])).getOption().series[0].type;
         }*/
         var options = [];
         var sigleOption = {};
         sigleOption = this.mapInitOption; // 實(shí)現(xiàn)深復(fù)制
         var colKeys = JSON.parse(JSON.stringify(ListAndList.colKeys));
         colKeys.pop();
         sigleOption.xAxis[0]["data"] = colKeys;
         var indicatorName = ListAndList.indicatorName;
         sigleOption["title"]["text"] = indicatorName;
         var series = [];
         for (var k = 0; k < ListAndList.rowKeys.length - 1; k++) { // 圖TTL指標(biāo)去掉
         var sigleSerie = {
         type : 'line',
         barMaxWidth : 40,
         barMinHeight : 15
         };
         var x = [];
         for (var z = 0; z < ListAndList.colKeys.length - 1; z++) {
         x.push(ListAndList.indicatorData[z][k]);
         }
         sigleSerie["name"] = ListAndList.rowKeys[k];
         sigleSerie["data"] = x;
         series.push(sigleSerie);
         }
         sigleOption["series"] = series;
         var legendData = JSON.parse(JSON.stringify(ListAndList.rowKeys));
         legendData.pop();
         sigleOption.legend.data = legendData;
         var unitHandle=ListAndList.indicatorUnit;
         sigleOption.tooltip.formatter=function (params,ticket,callback) {
         var myUnit =unitHandle;
         var color = params.color;
         var html = '<span style="display:inline-block;margin-right:5px;"'
         + '">行:'+params.seriesName +'</span><br>';
         html+='<span style="display:inline-block;margin-right:5px;"'
         + '">列:'+params.name +'</span><br>';
         var showValue = params.value;
         if (typeof (showValue) == "undefined") {
         showValue = "NoData";
         } else {
         // 圖懸浮框 千分位+萬 +單位
         if (!isNaN(showValue)) {
         if (showValue > 10000) {
         showValue = toThousands((showValue / 10000).toFixed(1)) + $.i18n.get('chart.wan')+myUnit;
         }else{
         if(unitHandle=='%'){
         showValue=parseFloat(showValue)*100;
         showValue = showValue.toFixed(1) + myUnit;
         }else{
         showValue = showValue.toFixed(1) + myUnit;
         }
         }
         }
         }
         html+='<span style="display:inline-block;margin-right:5px;"'
         + '">值:'+showValue +'</span>';
         return html;
         };
         return sigleOption;
         },
         convert : function (ev) {
         if (this.tableAndMap) {
         this.tableAndMap = false;
         } else {
         this.tableAndMap = true;
         }
         var indicatorName = this.mapOption.title.text;
         var myChart = echarts.init(document.getElementById([indicatorName]),rmp_theme);
         var grid = computerGrid(this.mapOption);
         myChart.resize({
         width : grid.chartWidth+"px",
         height : grid.chartHeight+"px"
         });
         myChart.setOption(this.mapOption);
         ev.stopPropagation();
         },
         exportExcel : function (ev) {
         var listAndList = JSON.parse(JSON.stringify(this.indicator));
         var rowTd = listAndList.rowKeys;
         var excellData = [];
         rowTd.splice(0, 0, listAndList.indicatorName+'('+listAndList.indicatorUnit+')');
         excellData.push(rowTd);
         for (var i = 0; i < listAndList.indicatorData.length; i++) {
         for(var j=0;j<listAndList.indicatorData[i].length;j++){
         listAndList.indicatorData[i][j]=cellsDeal(listAndList.indicatorData[i][j],listAndList.indicatorUnit);
         }
         var rowTr = listAndList.indicatorData[i];
         rowTr.splice(0, 0, listAndList.colKeys[i]);
         excellData.push(rowTr);
         }
         ExcellentExport.excelByData($("." + listAndList.indicatorName)[0], excellData, 'Sheet', 'download' + new Date().getTime() + '.xls');
         return ev.stopPropagation();
         }
         },
         watch : {
         indicator : function (newValue) {
         }
         },
         mounted : function () {
         // this.item= this.listToRowObject(this.indicator);
         },
         beforeMount : function(){
         this.item= this.listToRowObject(this.indicator);
         this.mapOption = this.listToRowMap(this.indicator);
         }
         })
         panelsVueArr.push(vueObj);
         } 
        }
        //格式化Y軸數(shù)字顯示
        var yAxisFormatter = function(value, index) {
         var text = value;
         if (!isNaN(value)) {
         if (value > 10000) {
         // 千分位 + 萬
         text = toThousands((value / 10000).toFixed(1)) + $.i18n.get('chart.wan');
         }
         }
         if (value.formatter) {
         text = value.formatter.replace("{value}", text);
         }
         return text;
        }
        //格式化tooltip
        var tooltipFormatter = function (params,ticket,callback) {
         console.log(params);
         var color = params.color;
         var html = '<span style="display:inline-block;margin-right:5px;' + 'border-radius:10px;width:9px;height:9px;background-color:'
         + color + '">行:'+params.seriesName +'</span>';
         html+='<span style="display:inline-block;margin-right:5px;' + 'border-radius:10px;width:9px;height:9px;background-color:'
         + color + '">列:'+params.name +'</span>';
         var showValue = params.value;
         if (typeof (showValue) == "undefined") {
         showValue = "NoData";
         } else {
         // 圖懸浮框 千分位+萬 +單位
         if (!isNaN(showValue)) {
         if (showValue > 10000||showValue<-10000) {
         showValue = toThousands((showValue / 10000).toFixed(1)) + $.i18n.get('chart.wan');
         }else{
         showValue=parseFloat(showValue)*100;
         showValue = showValue.toFixed(1) + unitHandle();
         }
         }
         }
         html+='<span style="display:inline-block;margin-right:5px;' + 'border-radius:10px;width:9px;height:9px;background-color:'
         + color + '">值:'+showValue +'</span>';
         console.log(html);
         return html;
        }
        // 數(shù)字格式處理 1,000,000
        function toThousands(num) {
         if (typeof (num) == 'undefined') {
         num = ""
         }
         num = num + '', result = '';
         if (num.indexOf('%') > -1) {
         return num;
         }
         var s = "";
         if (num.indexOf('.') > -1) {
         s = num.substring(num.indexOf('.'), num.length);
         num = num.substring(0, num.indexOf('.'));
         }
         var n = false;
         if (num.indexOf('-') > -1) {
         num = num.substring(1);
         n = true;
         }
         while (num.length > 3) {
         result = ',' + num.slice(-3) + result;
         num = num.slice(0, num.length - 3);
         }
         if (num != undefined) {
         result = num + result;
         }
         if (n) {
         result = "-" + result;
         }
         if(s=='.0'){
         return result;
         }
         return result + s;
        }
        // 千分位與單位處理
        function cellsDeal(num,unit) {
         if (typeof (num) == 'undefined') {
         num = "";
         }
         if(num===''){
         return num;
         }
         num = num + '', result = '';
         if (unit=='%') {
         num=parseFloat(num)*100;
         num = num.toFixed(1) + '';
         if(num.indexOf(".")!=-1){
         return num.substring(0,num.indexOf(".")+2)+"%";
         }else{
         return num+"%";
         }
         }
         var s = "";
         if (num.indexOf('.') > -1) {
         num=parseFloat(num).toFixed(1);
         s = num.substring(num.indexOf('.'), num.length); //小數(shù)位
         num = num.substring(0, num.indexOf('.')); //整數(shù)位
         }
         var n = false;
         if (num.indexOf('-') > -1) {
         num = num.substring(1);
         n = true;
         }
         while (num.length > 3) {
         result = ',' + num.slice(-3) + result;
         num = num.slice(0, num.length - 3);
         }
         if (num != undefined) {
         result = num + result;
         }
         if (n) {
         result = "-" + result;
         }
         if(unit.indexOf("/")!=-1){
         s=s.substring(0,2);
         }else{
         s="";
         }
         return result + s;
        }
        /*動(dòng)態(tài)計(jì)算echarts的grid屬性 */
        function computerGrid(options){
         // 圖寬度 默認(rèn)
         var chartWidth = 810;
         // 圖例占寬度比
         var legendWidth = chartWidth * 0.8;
         // 圖高度默認(rèn)
         var chartHeight = 250;
         // 圖中g(shù)rid離容器下邊距高度默認(rèn)
         var bottomHeight = 25;
         // 圖中g(shù)rid離容器上邊距高度默認(rèn)
         var topHeight = 40;
         // 根據(jù)x軸刻度數(shù)量 算寬度,如果超過默認(rèn) 則使用計(jì)算值
         if (options.xAxis[0].data.length * 30 - chartWidth > 0) {
         chartWidth = options.xAxis[0].data.length * 30;
         }
         // x軸刻度 最長的長度值
         var maxLength = 0;
         var legendCount = 8;
         if (options.xAxis[0].data.length > legendCount) {
         options.xAxis[0].data.forEach(function(val) {
         if (maxLength < val.length) {
         maxLength = val.length;
         if (/[^\u0000-\u00FF]/.test(val)) {
         // 計(jì)算圖中g(shù)rid離容器下邊距高度
         bottomHeight = maxLength * 14;
         } else {
         // 計(jì)算圖中g(shù)rid離容器下邊距高度
         bottomHeight = maxLength * 13.5;
         }
         }
         });
         }
         var tmpWidth = 0;
         options.legend.data.forEach(function(val) {
         if (/[^\u0000-\u00FF]/.test(val)) {
         tmpWidth += val.length * 22 + 30;
         } else {
         tmpWidth += val.length * 11 + 30;
         }
         });
         var rowNum = tmpWidth / legendWidth;
         // 根據(jù)圖例算 圖中g(shù)rid離容器上邊距高度
         if (rowNum > 1) {
         topHeight += (rowNum - 1) * 23;
         }
         chartHeight += bottomHeight + topHeight;
         options.legend['width'] = legendWidth;
         options.grid.y2 = bottomHeight;
         options.grid.y = topHeight;
         if(chartWidth!='810'){
         options.grid["x"]=40;
         }
         var columnAndRow = ['startProvince','startArea']; //始發(fā)省份和地區(qū)默認(rèn)X軸旋轉(zhuǎn)45度
         if(options.xAxis[0].data[0].match('^(\\d+)\\+(\\d+)')!=null||columnAndRow.indexOf(column.code)!=-1||columnAndRow.indexOf(row.code)!=-1){
         options.xAxis[0].axisLabel['rotate']=45;
         }else{
         options.xAxis[0].axisLabel['rotate']=0;
         }
         return {chartHeight:chartHeight,chartWidth:chartWidth};
        }

        上述代碼實(shí)現(xiàn)了 echart圖數(shù)據(jù)的格式化,和對數(shù)據(jù)的自適應(yīng)。修改為上述方式之后發(fā)現(xiàn)性能提高了不止一個(gè)數(shù)量級。

        以上這篇VUE2.0+Element-UI+Echarts封裝的組件實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

        聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        VUE2.0+Element-UI+Echarts封裝的組件實(shí)例

        VUE2.0+Element-UI+Echarts封裝的組件實(shí)例:本文用Vue2.0+elementUI的panel組件和table組件+echarts的柱狀圖和折線圖實(shí)現(xiàn)對結(jié)果的展示,實(shí)現(xiàn)了表格和圖之間的切換和圖和表之間的轉(zhuǎn)置。 -html <div class=resultDiv> <div id=panels> <el-colla
        推薦度:
        標(biāo)簽: VUE 封裝 組件
        • 熱門焦點(diǎn)

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 另类专区另类专区亚洲| 免费精品国产自产拍在线观看 | 33333在线亚洲| 精品一区二区三区无码免费直播| 丝袜捆绑调教视频免费区| 99re6在线精品视频免费播放| 在线免费观看一级片| 久久久久国产亚洲AV麻豆| 亚洲大香伊人蕉在人依线| eeuss在线兵区免费观看| 手机看黄av免费网址| 亚洲美女在线国产| 亚洲日本国产综合高清| 三级毛片在线免费观看| 亚洲中文字幕无码一区| 国产精品亚洲精品日韩动图| 国产精品公开免费视频| 亚洲激情电影在线| 最近国语视频在线观看免费播放| 麻豆国产入口在线观看免费| 久久久久亚洲AV无码麻豆| h片在线播放免费高清| 国产亚洲大尺度无码无码专线 | 国产成人免费在线| 日本大片在线看黄a∨免费| 亚洲自偷精品视频自拍| 9i9精品国产免费久久| 日韩黄色免费观看| 九九九精品视频免费| 国产一区二区三区在线免费观看 | 亚洲精品人成网线在线播放va| xxxx日本免费| 亚洲七久久之综合七久久| 免费精品国产自产拍在线观看图片| 99久久国产亚洲综合精品| 亚洲国产成人五月综合网| 国产精品亚洲一区二区三区久久 | 一级看片免费视频囗交| 亚洲AV无码一区二区乱子伦| 中文字幕免费人成乱码中国| 99久久亚洲综合精品成人网|