Taro React使用echarts 词云

1 篇文章 0 订阅
1 篇文章 0 订阅

Taro React使用echarts 词云

组件网址

echarts-wordcloud
echarts-for-react

安装组件和配置

npm install echarts
npm install echarts-wordcloud
npm install --save echarts-for-react

引用

import ReactEcharts from 'echarts-for-react';
import * as echarts from "echarts";
import "echarts-wordcloud";

使用方法

class wordcloud extends Component {
  wordOption(){
  
    let wordData = [
      {
        name: "游戏",
        value: 4220000
      },
      {
        name: "美食",
        value: 16681
      },
      {
        name: "衣服",
        value: 4386
      },
      {
        name: "鞋子",
        value: 222055
      },
      {
        name: "零食",
        value: 233467
      },
      {
        name: "化妆品",
        value: 66662244
      },
      {
        name: "吃货",
        value: 18298
      },
      {
        name: "美食家",
        value: 1488884
      },
      {
        name: "程序猿",
        value: 999999999
      },
      {
        name: "肝帝",
        value: 182298
      },
      {
        name: "老师",
        value: 144884
      },
      {
        name: "宠物",
        value: 15622355
      }
    ]

    let option = {
      backgroundColor: "#fff",
      tooltip: {
        pointFormat: "{series.name}: <b>{point.percentage:.1f}%</b>"
      },
      series: [
        {
          type: "wordCloud",
          gridSize: 1,
          sizeRange: [12, 55],
          rotationRange: [-45, 0, 45, 90],
          textStyle: {
            normal: {
              color: function () {
                return (
                  "rgb(" +
                  Math.round(Math.random() * 255) +
                  ", " +
                  Math.round(Math.random() * 255) +
                  ", " +
                  Math.round(Math.random() * 255) +
                  ")"
                );
              }
            }
          },
          left: "center",
          top: "center",
          right: null,
          bottom: null,
          width: "90%",
          height: "110%",
          data: wordData
        }
      ]
    };
    return option;
  };

  render() {
  
    return (
       <View className='word-chart'>
                <ReactEcharts
                  option={this.wordOption()}
                  theme='ThemeStyle'
                />
       </View>)}
}

在这里插入图片描述

  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值