水球图 及各种参数设置

8,649次阅读
没有评论

共计 3177 个字符,预计需要花费 8 分钟才能阅读完成。

水球图 (Liquid Fill Chart) 是 Echarts 的一个插件(在官方文档中没有),可以用来优雅的展示百分比数据。

水球图.gif

安装

HTML 中引入水球图:

其中这两个文件都可以在官方 github 项目中 dist 目录下获取到,echarts、echarts-liquidfill。

通过 npm 引入:

npm install echarts
npm install echarts-liquidfill

注意:echarts-liquidfill@3 版本匹配 echarts@5 版本,echarts-liquidfill@2 版本匹配 echarts@4 版本

最简单的例子

const option ={
    series:[{type:'liquidFill',
        data:[0.6]}]};

像其他 echarts 图配置一样,都需要配置 type 属性

简单例子.gif

多个波浪效果

const option ={
    series:[{type:'liquidFill',
        data:[0.6,0.5,0.4,0.3]}]};

通过传入多个数据值来展示多个数值或制造多个波浪的效果

多个波浪效果.gif

静止的波浪效果

const option ={
    series:[{type:'liquidFill',
        waveAnimation:false,
        animationDuration:0,
        animationDurationUpdate:0,
        data:[0.6,0.5,0.4,0.3]}]};

通过设置 waveAnimation 属性为 false,可以实现静止的波浪效果,另外,通过设置 animationDuration 和 animationDurationUpdate 属性的值,可以调整波浪的动画,同样可以实现静止的效果。

静止的波浪效果.gif

静止水面效果

const option ={
    series:[{type:'liquidFill',
        data:[0.6,0.5,0.4,0.3],
        amplitude:0,
        waveAnimation:0}]};

通过设置 amplitude(振幅) 属性可以实现水面的效果

静止水面效果.gif

其他形状的水球图

水球图不仅能被设定为圆形,也可以被设置为其他形状,如矩形、钻石菱形、箭头型等,也可以设置为包含其容器的形状,甚至可以通过 SVG 来设定

const options =[{
    series:[{type:'liquidFill',
        data:[0.6,0.5,0.4,0.3],
        shape:'diamond'}]}];

钻石菱形.gif

const option ={
    series:[{
        type:'liquidFill',
        data:[0.6,0.55,0.4,0.25],
        radius:'60%',
        outline:{show:false},
        backgroundStyle:{
            borderColor:'#156ACF',
            borderWidth:1,
            shadowColor:'rgba(0, 0, 0, 0.4)',
            shadowBlur:20},
        shape:'path://M367.855,428.202c-3.674-1.385-7.452-1.966-11.146-1.794c0.659-2.922,0.844-5.85,0.58-8.719 c-0.937-10.407-7.663-19.864-18.063-23.834c-10.697-4.043-22.298-1.168-29.902,6.403c3.015,0.026,6.074,0.594,9.035,1.728 c13.626,5.151,20.465,20.379,15.32,34.004c-1.905,5.02-5.177,9.115-9.22,12.05c-6.951,4.992-16.19,6.536-24.777,3.271 c-13.625-5.137-20.471-20.371-15.32-34.004c0.673-1.768,1.523-3.423,2.526-4.992h-0.014c0,0,0,0,0,0.014 c4.386-6.853,8.145-14.279,11.146-22.187c23.294-61.505-7.689-130.278-69.215-153.579c-61.532-23.293-130.279,7.69-153.579,69.202 c-6.371,16.785-8.679,34.097-7.426,50.901c0.026,0.554,0.079,1.121,0.132,1.688c4.973,57.107,41.767,109.148,98.945,130.793 c58.162,22.008,121.303,6.529,162.839-34.465c7.103-6.893,17.826-9.444,27.679-5.719c11.858,4.491,18.565,16.6,16.719,28.643 c4.438-3.126,8.033-7.564,10.117-13.045C389.751,449.992,382.411,433.709,367.855,428.202z',
        label:{position:['38%','40%'],formatter:function(){return'EChartsnLiquid Fill';},
            fontSize:40,
            color:'#D94854'}}]};

使用 svg.gif

API

默认水球图的配置

{data: [],

    color: ['#294D99', '#156ACF', '#1598ED', '#45BDFF'],
    center: ['50%', '50%'],
    radius: '50%',
    amplitude: '8%',
    waveLength: '80%',
    phase: 'auto',
    period: 'auto',
    direction: 'right',
    shape: 'circle',

    waveAnimation: true,
    animationEasing: 'linear',
    animationEasingUpdate: 'linear',
    animationDuration: 2000,
    animationDurationUpdate: 1000,

    outline:{show: true,
        borderDistance: 8,
        itemStyle:{color:'none',borderColor:'#294D99',borderWidth: 8,shadowBlur: 20,shadowColor:'rgba(0, 0, 0, 0.25)'}},

    backgroundStyle:{color:'#E3F7FF'},

    itemStyle:{opacity: 0.95,shadowBlur: 50,shadowColor:'rgba(0, 0, 0, 0.4)'},

    label:{show: true,color:'#294D99',insideColor:'#fff',fontSize: 50,fontWeight:'bold',align:'center',baseline:'middle'position:'inside'},

    emphasis:{itemStyle:{opacity: 0.8}}}

部分属性:

  • shape {string}
    波浪形状,可被设置为 ’circle’, ‘rect’, ’roundRect’, ‘triangle’, ‘diamond’, ‘pin’, ‘arrow’ 或者 svg 路径

作者:HEY_439

链接:https://www.jianshu.com/p/172b79fa33fe

来源:简书

著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

原文地址: 水球图 及各种参数设置

    正文完
     0
    Yojack
    版权声明:本篇文章由 Yojack 于2024-10-30发表,共计3177字。
    转载说明:
    1 本网站名称:优杰开发笔记
    2 本站永久网址:https://yojack.cn
    3 本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长进行删除处理。
    4 本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
    5 本站所有内容均可转载及分享, 但请注明出处
    6 我们始终尊重原创作者的版权,所有文章在发布时,均尽可能注明出处与作者。
    7 站长邮箱:laylwenl@gmail.com
    评论(没有评论)