项目实训(四)Echarts水球图与词云

本文介绍了如何在项目中使用Echarts的水球图和词云组件。首先,通过npm安装echarts-liquidfill和echarts-wordcloud,然后分别引入并根据官方文档创建水球图和词云的示例数据。水球图展示了不同数据值,词云则利用jieba分词器进行分词并展示词频。
摘要由CSDN通过智能技术生成

一、水球图下载使用

水球图官方地址https://github.com/ecomfe/echarts-liquidfill

在项目文件夹中运行npm install echarts-liquidfill
引入水球图import 'echarts-liquidfill’

依据下面官方文档绘制
var option = {
series: [{
type: ‘liquidFill’,
name: ‘Liquid Fill’,
data: [{
name: ‘First Data’,
value: 0.6
}, 0.5, 0.4, 0.3],
label: {
formatter: function(param) {
return param.seriesName + ‘\n’
+ param.name + ‘\n’
+ ‘Value:’ + param.value;
},
fontSize: 28
}
}]
};
更详细的参照官网文档

二、词云下载使用

词云官方地址https://github.com/ecomfe/echarts-wordcloud

在项目文件夹中运行npm install echarts-wordcloud
引入词云import 'echarts-wordcloud’

使用python jieba分词器分词,得到词汇和对应频率

依据下面官方文档代码绘制

series: [{
        type: 'wordCloud',

        // The shape of the "cloud" to draw. Can be any polar equation represented as a
        // callback function, or a keyword present. Available presents are circle (default),
        // cardioid (apple or heart shape curve, the most known polar equation), diamond (
        // alias of square), triangle-forward, triangle, (alias of triangle-upright, pentagon, and star.

        shape: 'circle',

        // A silhouette image which the white area will be excluded from drawing texts.
        // The shape option will continue to apply as the shape of the cloud to grow.

        maskImage: maskImage,

        // Folllowing left/top/width/height/right/bottom are used for positioning the word cloud
        // Default to be put in the center and has 75% x 80% size.

        left: 'center',
        top: 'center',
        width: '70%',
        height: '80%',
        right: null,
        bottom: null,

        // Text size range which the value in data will be mapped to.
        // Default to have minimum 12px and maximum 60px size.

        sizeRange: [12, 60],

        // Text rotation range and step in degree. Text will be rotated randomly in range [-90, 90] by rotationStep 45

        rotationRange: [-90, 90],
        rotationStep: 45,

        // size of the grid in pixels for marking the availability of the canvas
        // the larger the grid size, the bigger the gap between words.

        gridSize: 8,

        // set to true to allow word being draw partly outside of the canvas.
        // Allow word bigger than the size of the canvas to be drawn
        drawOutOfBound: false,

        // If perform layout animation.
        // NOTE disable it will lead to UI blocking when there is lots of words.
        layoutAnimation: true,

        // Global text style
        textStyle: {
            fontFamily: 'sans-serif',
            fontWeight: 'bold',
            // Color can be a callback function or a color string
            color: function () {
                // Random color
                return 'rgb(' + [
                    Math.round(Math.random() * 160),
                    Math.round(Math.random() * 160),
                    Math.round(Math.random() * 160)
                ].join(',') + ')';
            }
        },
        emphasis: {
            focus: 'self',

            textStyle: {
                shadowBlur: 10,
                shadowColor: '#333'
            }
        },

        // Data is an array. Each array item must have name and value property.
        data: [{
            name: 'Farrah Abraham',
            value: 366,
            // Style of single text
            textStyle: {
            }
        }]
    }]

没调样式乱乱的
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值