微信小程序echarts

git库

https://github.com/ecomfe/echarts-for-weixin

打不开用我这个

https://files.cnblogs.com/files/blogs/743986/echarts-for-weixin-master.zip

如果需要根据接口给的数据渲染

import * as echarts from "../../../components/echarts/echarts"
let chart = null;

Page({
  data: {
    option: {},
    ec: {}
  },
  onLoad() {
    this.getData()
  },
  // 初始化图表
  initChart(canvas, width, height, dpr) {
    chart = echarts.init(canvas, null, {
      width: width,
      height: height,
      devicePixelRatio: dpr // new
    });
    canvas.setChart(chart);
    chart.setOption(this.data.option);
    return chart;
  },
  getData() {
    let res = data;//接口获取的数据
    this.setData({
      option: res.data.option
    })
    // 获取option以后再渲染
    this.setData({
      ec: {
        onInit: this.initChart
      }
    })
  }

})

 

posted @ 2022-11-30 11:12  jqynr  阅读(33)  评论(0)    收藏  举报