// pages/components/curve-echarts/index.js import * as echarts from '../../../ec-canvas/echarts' Component({ /** * 组件的属性列表 */ properties: { chartId:{ type: String }, chartData:{ type: Object }, height:{ type:String } }, observers: { chartData: function (val) { this.initChart() }, }, /** * 组件的初始数据 */ data: { ec: { lazyLoad: true }, chart:undefined, }, lifetimes: { created: function(){ //在组件实例刚刚被创建时执行,注意此时不能调用 setData }, attached: function () { //在组件实例进入页面节点树时执行 }, ready: function () { // 在组件在视图层布局完成后执行 this.initChart(); }, detached: function () { // 在组件实例被从页面节点树移除时执行 }, }, /** * 组件的方法列表 */ methods: { initChart(){ var id ='#' + this.data.chartId; this.component = this.selectComponent(id); this.component.init((canvas, width, height, dpr) => { let chart = echarts.init(canvas, null, { width: width, height: height, devicePixelRatio: dpr }) chart.setOption(this.getData()); return chart; }) }, getData() { let that=this var data = this.data.chartData var legend={} var xAxis={} var series=[] if(data.lineData != undefined) { for(let i=0;i