专栏首页搞前端的李蚊子在echarts3中使用字符云

在echarts3中使用字符云

echarts2的官方API里是带有字符云的,但到了echarts3就被从官网上移除了,想要使用的话可以从github上下载:

下载地址:https://github.com/ecomfe/echarts-wordcloud

使用方法:

1.依次引入echarts.min.js和echarts-wordcloud.min.js(文件位置:下载的压缩包下dist/echarts-wordcloud.min.js);

<script src="echarts.min.js"></script>
<script src="echarts-wordcloud.min.js"></script>

2.自己翻译的简易说明(供参考)

 width---字符云画布宽度

 height---字符云画布宽度

maskImage---剪影图像,白色区域将被排除在绘图文本之外,形状选项将继续应用为云的形状。

如:

var maskImage = new Image();  
            //var world_option = world_cloud(eval('(' +  '${cloud}' + ')'),maskImage);  
            var world_option = world_cloud(data,maskImage);  
            maskImage.onload = function () {  
                world_option.series[0].maskImage  
                worldChart.setOption(world_option);  
            }  
            maskImage.src = 'img/ren1.png';  

gridSize---字符之间的间距(int)

sizeRange---字符的范围(array)

rotationRange---字符倾斜的角度(array)

3.实例:

var chart = echarts.init(document.getElementById('main'));

chart.setOption({
    ...
    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,

        // Global text style
        textStyle: {
            normal: {
                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: {
                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: {
                normal: {},
                emphasis: {}
            }
        }]
    }]
});

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • 假如用王者荣耀的方式学习webpack

    崴博.派克诞生于遥远西方的勇士之地,拥有着高超的机械技艺,善于运用各种工具来实现一些看似不可能完成的事。游历王者大陆时机缘巧合遇到了年轻的墨子,与之成为好友。后...

    李文杨
  • 小程序获取微信用户绑定的手机号

    小程序API内提供getPhoneNumber借口来获取用户已经绑定到微信的手机号,但需要用户主动触发才能发起获取手机号接口,所以该功能不由 API 来调用; ...

    李文杨
  • 微信返回码说明

    返回码说明 返回码    说明 -1     系统繁忙 0     请求成功 40001     验证失败 40002     不合法的凭证类型 40003  ...

    李文杨
  • What do we mean by “understanding” something?

    In this chapter, we shall examine the most fundamental ideas that we have about ...

    一个会写诗的程序员
  • 研发:What is a DDoS Attack?

    A distributed denial-of-service (DDoS) attack is a malicious attempt to disrupt ...

    heidsoft
  • Using LDA for classification使用LDA线性判别分析来分类

    Linear Discriminant Analysis (LDA) attempts to fit a linear combination of featu...

    到不了的都叫做远方
  • 追踪接触者以控制COVID-19大流行(CS SI)

    控制 COVID-19大流行需要大量减少接触,主要是通过实施行动控制达到强制隔离的水平。 这导致了经济的大部分崩溃。这种疾病的携带者大约在接触病毒后3天具有传染...

    用户7095611
  • 卷积神经网络反向传播推导

    Disclaimer: It is assumed that the reader is familiar with terms such as Multila...

    量化投资与机器学习微信公众号
  • Using many Decision Trees – random forests使用多棵决策树--随机森林

    In this recipe, we'll use random forests for classification tasks. random forest...

    到不了的都叫做远方
  • 研发:Idea工具因为版本工具设置问题,导致全是红色

    I have the current status of my files in the folders coloured red/brown. I tried...

    heidsoft

扫码关注云+社区

领取腾讯云代金券