🪀 Uni ECharts:也许是 uni-app 中使用 ECharts 最优雅的解决方案

Uni ECharts 是适用于 uni-app 的 Apache ECharts 组件,无需繁琐的步骤即可轻松在 uni-app 平台上使用 echarts。

🎉 特性

  • 🚀 快速上手,与 Vue ECharts 近乎一致的使用体验
  • 📱 多端兼容,支持 Web、小程序、APP
  • 📦 支持 easycom
  • ☕ 支持 TypeScript
  • 🍳 支持免费商用

🚀 快速开始

前置条件:

  • echarts >= 5.3.0
  • vue >= 3.3.0

安装

  1. 使用 npm 安装 echarts
shell 复制代码
# pnpm
pnpm add echarts

# yarn
yarn add echarts

# npm
npm install echarts
  1. 前往 uni-app 插件市场下载 Uni Echarts

配置

Uni ECharts 支持 easycom 规范, 当使用 uni-modules 方式时无需配置即可免导入直接使用组件。

使用

html 复制代码
<template>
  <uni-echarts custom-class="chart" :option="option"></uni-echarts>
</template>

<script setup>
import { PieChart } from "echarts/charts";
import { DatasetComponent, LegendComponent, TooltipComponent } from "echarts/components";
import { use } from "echarts/core";
import { CanvasRenderer } from "echarts/renderers";
import { ref } from "vue";
import { provideEchartsTheme } from "@/uni_modules/xiaohe-echarts";

// 此处仅用于演示通过 provide 修改图表 theme 的方式,不是必需
provideEchartsTheme("dark");

use([
  LegendComponent,
  TooltipComponent,
  DatasetComponent,
  PieChart,
  CanvasRenderer
]);

const option = ref({
  legend: {
    top: 10,
    left: "center"
  },
  tooltip: {
    trigger: "item",
    textStyle: {
      // #ifdef MP-WEIXIN
      // 临时解决微信小程序 tooltip 文字阴影问题
      textShadowBlur: 1
      // #endif
    }
  },
  series: [
    {
      type: "pie",
      radius: ["30%", "52%"],
      label: {
        show: false,
        position: "center"
      },
      itemStyle: {
        borderWidth: 2,
        borderColor: "#ffffff",
        borderRadius: 10
      },
      emphasis: {
        label: {
          show: true,
          fontSize: 20
        }
      }
    }
  ],
  dataset: {
    dimensions: ["来源", "数量"],
    source: [
      ["Search Engine", 1048],
      ["Direct", 735],
      ["Email", 580],
      ["Union Ads", 484],
      ["Video Ads", 300]
    ]
  }
});
</script>

<style scoped>
.chart {
  height: 300px;
}
</style>

🌴 ECharts

按需导入

由于小程序对于代码体积的要求非常严苛,所以我们鼓励手动从 echarts 中按需导入组件和图表,以减小打包体积。 Vue ECharts 团队构建了一个 导入代码生成器, 你只需要把 option 的代码粘贴进去,就可以得到精确的导入代码。试一试

但如果你实在需要全量引入 echarts 从而无需手动导入模块,只需要在代码中添加:

js 复制代码
import "echarts";

🔗 链接

🌟 支持鼓励

如果 Uni ECharts 对你有帮助,可以通过以下渠道对我们表示鼓励:

🍬 鸣谢

得益于以下项目对开源的付出,让 Uni ECharts 能够站在巨人的肩膀上。

🐶 讨论交流

  • ❓:若有疑问或 BUG 反馈,可提交 issues,也欢迎 PR
  • 🐧:暂未开通

🏆 开源协议

Uni ECharts 基于 MIT 许可发布,请自由地享受和参与开源。

🚓 声明

The Apache Software Foundation Apache ECharts, ECharts, Apache, the Apache feather, and the Apache ECharts project logo are either registered trademarks or trademarks of the Apache Software Foundation.

相关推荐
2501_916007473 小时前
iOS 混淆实战,多工具组合完成 IPA 混淆、加固与发布治理(iOS混淆|IPA加固|无源码混淆|App 防反编译)
android·ios·小程序·https·uni-app·iphone·webview
2501_915918413 小时前
怎么上架 App?iOS 应用上架完整流程详解与跨平台发布实战指南
android·ios·小程序·https·uni-app·iphone·webview
2501_916008893 小时前
iOS 混淆工具链实战 多工具组合完成 IPA 混淆与加固(iOS混淆|IPA加固|无源码加固|App 防反编译)
android·ios·小程序·https·uni-app·iphone·webview
SY_FC4 小时前
uniapp textarea标签 在ios真机上出现高度拉长问题
uni-app
游戏开发爱好者813 小时前
HTTPS 内容抓取实战 能抓到什么、怎么抓、不可解密时如何定位(面向开发与 iOS 真机排查)
android·网络协议·ios·小程序·https·uni-app·iphone
shykevin21 小时前
uni-app x导航区域跳转
windows·uni-app
2501_915106321 天前
iOS 混淆与 IPA 加固全流程,多工具组合实现无源码混淆、源码防护与可审计流水线(iOS 混淆|IPA 加固|无源码加固|App 防反编译)
android·ios·小程序·https·uni-app·iphone·webview
游戏开发爱好者81 天前
用多工具组合把 iOS 混淆做成可复用的工程能力(iOS混淆 IPA加固 无源码混淆 Ipa Guard)
android·ios·小程序·https·uni-app·iphone·webview
2501_915921431 天前
掌握 iOS 26 App 性能监控,从监测到优化的多工具组合流程
android·macos·ios·小程序·uni-app·cocoa·iphone
勉灬之1 天前
通过npm run XXX命令生成uniapp的pages.json文件
npm·uni-app·json