uniapp微信小程序使用echarts教程

5小时前   阅读:45   类型:前端   分类:uni-app    标签: 微信小程序 Vue uni-app

echarts 全端兼容,一款使echarts图表能跑在uniapp各端中的插件, 支持uniapp/uniappx(web,ios,安卓,鸿蒙),本文介绍如何在uniapp中使用echarts,可自由选择所需图表、坐标系、组件进行打包下载。

一、下载扩展包

可以选插件内完整的echarts包

或自定义包,自定义包下载地址:https://ext.dcloud.net.cn/plugin?id=4899

二、将扩展包放置指定路径

这里放在项目根目录/lime-echart

三、页面扩展包引入

<script>
import * as echarts from '@/lime-echart/static/echarts.min'
</script>

四、页面代码

<template>
<!-- 图表 -->
      <view style="width:750rpx; height:550rpx"><l-echart ref="chartRef" @finished="init"></l-echart></view>
<!-- 图表 -->
</template>

五、js代码

<script>
export default {
  data() {
    return {

    };
  },
  // 组件能被调用必须是组件的节点已经被渲染到页面上
  methods: {
    async init() {
       const chart = await this.$refs.chartRef.init(echarts); // 根据索引获取不同的 ref
 var option= {
 color:'#ed0046',
  xAxis : [
  {
  type : 'category',
  data : ['2025-10-21','2025-10-20','2025-10-19'],
  boundaryGap: false,
  }
  ],
  yAxis : [
  {
  type : 'value',
  x: 'center',
  splitLine: {
 lineStyle: {
  type: 'dashed'
 }
  }
  },
   
  ],
  series: [
  {
  type:'line',
  smooth: true,
  data:['100','80','60'],
  areaStyle: {
 color:'#f7c7d5',
  }
  }
  ]
 }
 chart.setOption(option)
    }
  }
}
</script>

六、完整代码:折线统计图

<template>
<!-- 图表 -->
<view style="width:750rpx; height:550rpx"><l-echart ref="chartRef" @finished="init"></l-echart></view>
<!-- 图表 -->
</template>
<script>
import * as echarts from '@/lime-echart/static/echarts.min'
export default {
  data() {
    return {

    };
  },
  methods: {
    async init() {
       const chart = await this.$refs.chartRef.init(echarts); // 根据索引获取不同的 ref
 var option= {
 color:'#ed0046',
  xAxis : [
  {
  type : 'category',
  data : ['2025-10-21','2025-10-20','2025-10-19'],
  boundaryGap: false,
  }
  ],
  yAxis : [
  {
  type : 'value',
  x: 'center',
  splitLine: {
 lineStyle: {
  type: 'dashed'
 }
  }
  },
   
  ],
  series: [
  {
  type:'line',
  smooth: true,
  data:['100','80','60'],
  areaStyle: {
 color:'#f7c7d5',
  }
  }
  ]
 }
 chart.setOption(option)
    }
  }
}
</script>
【腾讯云】AI 驱动 · 智领未来,4核4G3M云服务器低至 79元/年

‘简忆博客’微信公众号 扫码关注‘简忆博客’微信公众号,获取最新文章动态
转载:请说明文章出处“来源简忆博客”。http://www.tpxhm.com/fdetail/1161.html

×
觉得文章有用就打赏一下文章作者
微信扫一扫打赏 微信扫一扫打赏
支付宝扫一扫打赏 支付宝扫一扫打赏

文章评论(0)

登录
简忆博客壁纸一
简忆博客壁纸二
简忆博客壁纸三
简忆博客壁纸四
简忆博客壁纸五
简忆博客壁纸六
简忆博客壁纸七
简忆博客壁纸八
头像

简忆博客
勤于学习,乐于分享

置顶推荐

打赏本站

如果你觉得本站很棒,可以通过扫码支付打赏哦!
微信扫码:你说多少就多少~
微信扫码
支付宝扫码:你说多少就多少~
支付宝扫码
×