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

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

相关文章
为什么登不进去?
服务商模式下微信支付后关注服务商公众号功能取消了吗?还是暂时调整?
小程序如何防止僵尸微信号授权登录?如何防止灰产破坏行为?
微信内打开app,config:invalid url domain?
简直无语,从未见过这么离谱的拒审原因!?
随便看看
微信开放平台跟公众平台有什么区别? 3607
怎么添加小程序支付功能? 4516
教育科技公司申请微信支付被拒绝? 4798
微信公众号免300认证教程 5892
小程序已经上线,作为管理员无法在小程序数据助手查看数据? 5299
小程序广告组件通过审核,但是小程序内没有显示广告? 5067
企业微信通讯录账号被管理员误/恶意删除,怎么办? 9568
问题? 9047
如何快速搭建抽奖助手小程序(无需代码知识) 6177
许涛 大哥在吗, 要解冻小程序的时候提示信息主体不一致, 能帮忙看下吗? 7471