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

小程序 文章 2020-08-07 10:01 645 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


国内超级便宜服务器

摸鱼人热门新闻聚合

钻级赞助商 我要加入

开发者在线工具

第三方支付技术请加QQ群

相关文章
微信小游戏加载资源失败:download fail?
小商店是微信小程序的一种,流量来源里面注明了,全局搜索搜一搜,为什么我的小商店在搜一搜搜索不到?
公众号开发网页授权redirect_uri参数错误?
BackgroundAudioManager如何在iOS静音模式下正常播放?
请问以下方框样式如何实现?
随便看看
自定义交易组件 新流程中必须要使用小程序进行支付吗? 413
怎么制作小程序? 310
为什么我的数组总是乱序? 443
macOS升级12.3.1 之后企业微信一直闪退 1698
在网上找到了一个openid的获取方法,但是最后的传参不会写,有大佬可以帮帮吗? 354
小程序类型为IT科技,软件服务提供商,如何开通小程序直播 ?,没有支付记录 345
试用转正后的小程序,登录公众号后台后,为什么不能修改小程序基本信息? 316
微信云托管的mysql数据库为什么在小程序中不能用内网IP连接? 1048
微信小程序进行的银行存款有保障吗? 1686
请问苹果手机小程序为什么不能添加到桌面? 611