npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

mpvue-echarts2

v0.0.9

Published

适用于 Mpvue 的 ECharts 组件,支持小程序新 Canvas 2D 接口

Downloads

12

Readme

在微信小程序中使用 ECharts

mpvue-echarts: 本项目是 ECharts 的 Mpvue 小程序版本。开发者可以通过熟悉的 ECharts 配置方式及 Vue 语法,快速开发图表,满足各种可视化需求。

mpvue-echarts2: 本项目是原项目 mpvue-echarts 以及 Echarts 官方小程序原生版本 echarts-for-weixin 缝合版本,支持小程序新 Canvas 2D 接口。

npm package npm downloads

扫码体验

mpvue-echarts

小程序码

echarts-for-weixin

小程序码

安装

npm i mpvue-echarts2

使用

<template>
  <div class="echarts-wrap">
    <mpvue-echarts2 :echarts="echarts" :onInit="onInit" canvasId="demo-canvas" />
  </div>
</template>

<script>
import echarts from 'echarts'
import mpvueEcharts2 from 'mpvue-echarts2'

let chart = null;

function initChart(canvas, width, height, canvasDpr) {
  chart = echarts.init(canvas, null, {
    width: width,
    height: height,
    canvasDpr: canvasDpr // 增加了dpr
  });
  canvas.setChart(chart);

  var option = {}; // ECharts 配置项

  chart.setOption(option);

  return chart; // 返回 chart 后可以自动绑定触摸操作
}

export default {
  components: {
    mpvueEcharts2
  },
  data () {
    return {
      echarts,
      onInit: initChart
    }
  }
}
</script>

<style scoped>
.echarts-wrap {
  width: 100%;
  height: 300px;
}
</style>

这对于所有 ECharts 图表都是通用的,用户只需要修改上面 option 的内容,即可改变图表。option 的使用方法参见 ECharts 配置项文档。对于不熟悉 ECharts 的用户,可以参见 5 分钟上手 ECharts 教程。

属性

| 名称 | 类型 | 默认值 | 描述 | | -------------|--------------- | ------------- | ------------- | | echarts | Object | null | echarts 对象 | | canvasId | String | ec-canvas | canvasId | | onInit | Function | null | 初始化函数 | | lazyLoad | Boolean | false | 懒加载 | | disableTouch | Boolean | false | 禁用触摸事件 | | throttleTouch| Boolean | false | 节流触摸事件 |

FAQ

[重要] 不要把 chart 实例赋值到 this(vue 实例) 上

如何获取图表实例?

echarts.init 返回的即为图表实例。

打包结果超过小程序大小限制?

使用自定义版 echarts,官网定制

如何延迟加载图表?

参见 examples/lazyLoad 的例子,可以在获取数据后再初始化数据。

注意将标签替换为mpvue-echarts2!

如何在一个页面中加载多个图表?

参见 examples/multiCharts 的例子。

注意将标签替换为mpvue-echarts2!

图表变空白?

尝试设置 throttleTouch 属性为 true

如何使用 Tooltip?

目前,本项目已支持 ECharts Tooltip,但是由于 ECharts 相关功能尚未发版,因此当前需要使用原项目中 ec-canvas/echarts.js,这个文件包含了可以在微信中使用 Tooltip 的相关代码。目前在 ECharts 官网下载的 echarts.js 还不能直接替换使用,等 ECharts 正式发版后即可。

具体使用方法和 ECharts 相同,例子参见 pages/line/index.js

文件太大怎么办?

本项目默认提供的 ECharts 文件是最新版本的包含所有组件文件,为了便于开发,提供的是未压缩的版本。远程调试或预览可以下载 echarts.min.js 压缩版本。

发布时,如果对文件大小要求更高,可以在 ECharts 在线定制 网页下载仅包含必要组件的包,并且选择压缩。

将压缩包置入node_modules/echarts/dict路径下,引入页面并以echarts参数传入组件

打包时出错 ERROR in static/js/vendor.js from UglifyJs

参照以下配置使 babel 处理 mpvue-echarts

// webpack.base.conf.js
{
  test: /\.js$/,
  include: [
    resolve('src'),
    resolve('node_modules/mpvue-echarts')
  ],
  use: [
    'babel-loader',
    {
      loader: 'mpvue-loader',
      options: {
        checkMPEntry: true
      }
    }
  ]
}

微信版本要求

Canvas 2d 版本要求

最新版的 ECharts 微信小程序支持微信 Canvas 2d,当用户的基础库版本 >= 2.9.0 且没有设置 force-use-old-canvas="true" 的情况下,使用新的 Canvas 2d(默认)。

使用新的 Canvas 2d 可以提升渲染性能,解决非同层渲染问题,这很重要,强烈建议开启

如果仍需使用旧版 Canvas,使用方法如下:

<mpvue-echarts2 :echarts="echarts" canvas-id="xxx" force-use-old-canvas></mpvue-echarts2>

支持微信版本 >= 6.6.3,对应基础库版本 >= 1.9.91。尽可能使用更高版本的基础库版本。

调试的时候,需要在微信开发者工具中,将“详情”下的“调试基础库”设为 1.9.91 及以上版本。

发布前,需要在 https://mp.weixin.qq.com 的“设置”页面,将“基础库最低版本设置”设为 1.9.91。当用户微信版本过低的时候,会提示用户更新。

暂不支持的功能

ECharts 中的绝大部分功能都支持小程序版本,因此这里仅说明不支持的功能,以及存在的问题。

以下功能尚不支持,如果有相关需求请在 issue 中向我们反馈,对于反馈人数多的需求将优先支持:

  • 图片
  • 多个 zlevel 分层

此外,目前还有一些 bug 尚未修复,部分需要小程序团队配合上线支持,但不影响基本的使用。已知的 bug 包括:

  • 安卓平台:transform 的问题(会影响关系图边两端的标记位置、旭日图文字位置等)
  • iOS 平台:半透明略有变深的问题
  • iOS 平台:渐变色出现在定义区域之外的地方

如有其它问题,也欢迎在 issue 中向我们反馈,谢谢!