1.0.0 • Published 4 years ago

taro-echarts-wf v1.0.0

Weekly downloads
3
License
MIT
Repository
-
Last release
4 years ago

Taro-Echarts-WF

适用于Taro项目的ECharts图表组件,基于项目echarts-for-weixin封装

安装

npm i -S taro-echarts-wf

配置

修改Taro项目的配置config/index

  1. copy
copy: {
  patterns: [
    // 需添加如下配置
    {
      from: 'node_modules/taro-echarts/components/ec-canvas/',
      to: 'dist/npm/taro-echarts/components/ec-canvas',
      ignore: ['ec-canvas.js', 'wx-canvas.js']
    }
  ],
  options: {
  }
}
  1. h5.esnextModules
h5: {
  // 需添加如下配置
  esnextModules: ['taro-echarts'],
  ...
}

使用

引入

import Chart from 'taro-echarts-wf'

示例代码:以折线图为例

<Chart
  option={{
    xAxis: {
      type: 'category',
      data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    },
    yAxis: {
      type: 'value'
    },
    series: [{
      data: [820, 932, 901, 934, 1290, 1330, 1320],
      type: 'line'
    }]
  }}
/>

API

属性名说明类型默认值
width图表的宽string100%
height图表的高string200px
optionECharts的option配置object-
onBeforeSetOption在echarts首次调用setOption前执行该方法,该方法会返回echarts的引用,可以在该方法中注册地图注册主题(echarts)=>void-
customStyle自定义容器样式string-
loading是否显示loading效果boolfalse
loadingConfloading效果的样式配置object-

支持度

h5微信小程序ReactNative支付宝小程序百度小程序字节跳动小程序
××××

微信小程序获取图片示例代码

import Taro, { Component } from '@tarojs/taro'
import { View, Button } from '@tarojs/components'
import Chart from 'taro-echarts-wf'

export default class Page extends Component {

  setChartRef = node => this.chartRef = node

  preview = async () => {
    // 获取到临时图片地址
    const path = await this.chartRef.getImagePath()
    Taro.previewImage({ current: path, urls: [path] })
  }

  render() {
    return (
      <View>
        <Button onClick={this.preview}>查看生成图片</Button>
        <Chart
          ref={this.setChartRef}
          loadingConf={{ textColor: 123 }}
          option={{
            xAxis: {
              type: 'category',
              data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
            },
            yAxis: {
              type: 'value'
            },
            series: [{
              data: [820, 932, 901, 934, 1290, 1330, 1320],
              type: 'line'
            }]
          }}
        />
      </View>
    )
  }
}

License

MIT