微信小程序中使用ECharts 并且动态设置数据

项目下载地址 GitHub 地址 https://github.com/ecomfe/echarts-for-weixin

将当前文件夹里的内容拷贝到项目中

目录:

json:

复制代码
{
  "usingComponents": {
    "ec-canvas": "../components/ec-canvas/ec-canvas"
  }
}

wxml:

复制代码
<ec-canvas id="eChart" canvas-id="eChart" ec="{{ ec }}"></ec-canvas>

js:

复制代码
import * as echarts from '../components/ec-canvas/echarts.js';
Page({
  data: {
    ec: {
      lazyLoad: true,
    }
  },
  onReady: function () {
    const num = 77
    this.initchart(num)
  },
  initchart(data) {
    let ec_canvas = this.selectComponent('#eChart');
    ec_canvas.init((canvas, width, height, dpr) => {
      const chart = echarts.init(canvas, null, {
        width: width,
        height: height,
        devicePixelRatio: dpr // new
      });
      canvas.setChart(chart);

      const option = {
        title: {
          text: ''
        },
        tooltip: {
          formatter: '{a} <br/>{b} : {c}%'
        },
        series: [
          {
            name: '评估',  // 设置环形进度条的名称
            type: 'gauge',
            radius: '80%',  // 设置环形的半径
            startAngle: -135,  // 设置起始角度为左下角
            endAngle: -45,  // 设置结束角度为右下角
            progress: {
              show: true,  // 显示进度条
              width: 10,  // 设置环形的宽度
              itemStyle: {
                // 使用 LinearGradient 设置渐变色
                color: new echarts.graphic.LinearGradient(0, 0, 1, 1, [
                  { offset: 0, color: '#61E5AB' },  // 渐变起始颜色
                  { offset: 1, color: '#228D7D' }   // 渐变结束颜色
                ])
              }
            },
            detail: {
              valueAnimation: true,  // 动画效果
              formatter: '{value}',  // 只显示值
              fontSize: 30,  // 设置字体大小
              color: '#333',  // 设置字体颜色
              offsetCenter: [0, '40%'],  // 设置文本位置
            },
            data: [
              {
                value: data
              }
            ],
            axisLine: {

            },
            axisTick: {
              show: false
            },
            axisLabel: {
              show: false,
              distance: 50
            },
            splitLine: {
              show: false  // 去掉分割线
            },
          }
        ]
      };

      chart.setOption(option);
      return chart;
    })
  },
}

结果:

相关推荐
程序鉴定师7 小时前
西安App开发推荐与业界认可的优秀实践
大数据·小程序
纤纡.13 小时前
HarmonyOS 鸿蒙 ArkTS 实战:从零开发生肖集卡抽奖小程序
华为·小程序·harmonyos·deveco studio
Lsx_13 小时前
H5 嵌入微信 / 支付宝 / 抖音小程序 WebView:调用原生能力完整方案
前端·微信小程序·webview
蜡台14 小时前
Vue3 + ECharts 实现地图显示,深蓝色科技风地图、涟漪点、向上连线 ,标签
vue.js·科技·echarts·map·地图
我是伪码农15 小时前
小程序26-50
小程序
计算机学姐1 天前
基于微信小程序的图书馆座位预约系统【uniapp+springboot+vue】
vue.js·spring boot·微信小程序·小程序·java-ee·uni-app·intellij-idea
焦糖玛奇朵婷1 天前
健身房预约小程序开发、设计
java·大数据·服务器·前端·小程序
Dragon Wu1 天前
Taro v4.2.0 scss使用“@/xxx“的配置方法
前端·小程序·taro·scss
WKK_1 天前
uniapp 微信小程序使用TextEncoder,arrayBufferToBase64
微信小程序·小程序·uni-app
盐多碧咸。。1 天前
echarts折线图矩形选择 框选图表
前端·javascript·echarts