自定义组件里个Echarts不行?直接报错没有setOption

小程序 文章 2020-08-07 10:01 639 0 全屏看文

AI助手支持GPT4.0

自定义组件里个Echarts不行?直接报错没有setOptionEcharts in the custom component is not good? No setOption is reported directly

自定义组件里个Echarts不行?直接报错没有setOption
import * as echarts from '../../../ec-canvas/echarts';let app = getApp()var barec = nullComponent({  /**   * 组件的属性列表   */  properties: {    btText: {      value: '默认值',      type: String    }  },  onShareAppMessage: function (res) {    return {      title: 'ECharts 可以在微信小程序中使用啦!',      path: '/pages/SysComponent/jixiao',      success: function () {},      fail: function () {}    }  },  /**   * 组件的初始数据   */  data: {    date: '请选择>', //默认起始时间      date2: '请选择>', //默认起始时间      listArr: [],    //barec:null,    windowHeight: '', //屏幕高度     scrollTop: 0, //设置srcoll-view距离顶部位置    ec: {    }  },  /**   * 组件的方法列表   */  methods: {    showLog: function () {      var that=this;      var widhegth = wx.getSystemInfoSync().windowHeight;      var listboxCount = parseInt(widhegth / 30);      that.setData({        windowHeight: widhegth,        pageSize: listboxCount,        ec:{          onInit: function (canvas, width, height) {            barec = echarts.init(canvas, null, { width: width, height: height            });            canvas.setChart(barec);            return barec;          }        }      })      var animation = wx.createAnimation({        duration: 1000,        timingFunction: "ease",        delay: 0      })      animation.translateY(5).step();      that.setData({        animationData: animation.export()      })      that.getData()    },    onReady() {      setTimeout(this.getData, 500);    },    getData() {      var that=this;      wx.showLoading({        title: '加载中...',      })           barec.setOption({ grid: {   left: '3%',   right: '7%',   bottom: '3%',   containLabel: true }, tooltip: {   // trigger: 'axis',   showDelay: 0,   formatter: function (params) {     if (params.value.length > 1) {       console.log(params)       return params.seriesName + ' :' +         params.value[0] + '个 ' +         params.value[1] + 'm ';     } else {       return params.name + ' :' +         params.seriesName + ' : ' +         params.value;     }   },   axisPointer: {     show: true,     type: 'cross',     lineStyle: {       type: 'dashed',       width: 1     }   } }, color: ["#37A2DA", "#67E0E3"], legend: {   data: ['个数', '次数'],   top: 20,   left: 'center',   backgroundColor: '#FFFFFF',   z: 100 }, xAxis: {   x: 'center',   type: 'value',   splitLine: {     lineStyle: {       type: 'dashed'     }   }   // show: false }, yAxis: {   type: 'category',   boundaryGap: false,   data: ["", "测试1", "测试2", "测试3", "测试4", "测试5", "测试6", "测试7", "测试8", "测试9", "测试10", "测试11", "测试12", "测试13", "测试14", "测试15", "测试16", "测试17", "测试18", "测试19", "测试20", "测试21", "王富贵", "测试22", "测试23", "测试24", "测试25", "测试26", "测试27", ""], //   // show: false   }, series: [{   name: '个数',   type: 'bar',   smooth: true,   data: EntNumber//[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 0] // }, {   name: '次数',   type: 'bar',   smooth: true,   data:[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 19, 0] // }]            },            wx.hideLoading())        },        fail: function (res) {},        complete: function (res) {},      })    }  }})

大佬们,帮忙看一下哪里出问题了呗,如果需要我看什么东西就能了解的话,告知一下我需要看哪里,谢谢大佬们了

Import * as charts from '/ / / / / EC Canvas / contracts'; let app = getapp() var barec = nullcomponent ({/ * * * component's property list * / properties: {bttext: {value:' default value ', type: String}}, onshareappmessage: function (RES) {return {Title:' ecarts can be used in wechat applet! ', path:' / pages / syscomponent / Jixiao ', success: function() {}, fail: function() {}}}, / * * initial data of components * / data: {date:' Please Select > '/ / default start time date2:' Please Select > '/ / default start time listarr: []// barec:null , windowheight '', / / screen height scrolltop: 0, //Set the srcol view distance from the top EC: {}}, / * * component method list * / METHODS: {showlog: function() {var that = this; VAR width= wx.getSystemInfoSync ().windowHeight; var listboxCount = parseInt(widhegth / 30); that.setData ({ windowHeight: widhegth, pageSize: listboxCount, ec:{ onInit: function (canvas, width, height) { barec = echarts.init (canvas, null, { width: width, height: height });canvas.setChart (barec); return barec; } } }) var animation = wx.createAnimation ({ duration: 1000, timingFunction: "ease", delay: 0 }) animation.translateY (5).step(); that.setData ({ animationData: animation.export () }) that.getData () }, onReady() { setTimeout( this.getData , 500); }, getData() { var that=this; wx.showLoading ({Title: 'loading...', }) barec.setOption ({ grid: { left: '3%', right: '7%', bottom: '3%', containLabel: true }, tooltip: { // trigger: 'axis', showDelay: 0, formatter: function (params) { if ( params.value.length > 1) { console.log (params) return params.seriesName + ' :' + params.value [0] +'pieces'+ params.value [1] + 'm '; } else { return params.name + ' :' + params.seriesName + ' : ' + params.value ; } }, axisPointer: { show: true, type: 'cross', lineStyle: { type: 'dashed', width: 1 } } }, Color: ["ා37a2da", "ාාාාාාාa2da", "ාාාාාa2da", "#ාාාා#a2da", "####a2da", "#####e0e3"], legend: {data: ['number ',' times']{ Linestyle: {type:'dashed '}} / / show: false}, yaxis: {type:'category', boundarygap: false, data: ["," test 1 "," test 2 "," test 3 "," test 4 "," test 5 "," test 6 "," test 7 ", "Test 8", "test 9", "test 10", "test 11", "test 12", "test 13", "test 14", "test 15", "test 16", "test 17", "test 18", "test 19", "test 20", "test 21", "Wang Fugui", "test 22", "test 23", "test 24", "test 25", "test 26", "test 27", "], / / show: false}, Series: [{Name: 'number', type: 'bar', smooth: true, data: entnumber / / [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 0] /}, {Name: 'times', type:' bar ', smooth: true, data:[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 19, 0] // }] },wx.hideLoading ()) }, fail: function (res) {}, complete: function (res) {}, }If you need me to see something that I can understand, please tell me where I need to see. Thank you

回答:

小卒过河〰:barec对象在你调用方法时为null 得在调用之前为它初始化,建议利用断点调试
微喵网络:

异步的问题

-EOF-

AI助手支持GPT4.0