echarts水球图内阴影与胶囊图制作

先贴代码后贴图,最后讲解

 

git地址以及文档

水球图:

<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>水泡图</title>

    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        html,
        body {
            width: 100%;
            height: 100%;
        }
        
        #container {
            width: 200px;
            height: 200px;
        }
    </style>
</head>

<body>
    <div id="container"></div>
    <script src="https://cdn.bootcss.com/echarts/4.7.0/echarts-en.min.js"></script>
    <script src="https://echarts.baidu.com/resource/echarts-liquidfill-latest/dist/echarts-liquidfill.min.js"></script>
</body>
<script>
    const options = {
        // 悬浮提示
        // tooltip: [],
        // color: [],
        // // 图例
        // legend: [],
        // // 横轴  
        // xAxis: [],
        // // 纵轴
        // yAxis: [],
        // 标题
        title: {
            text: (0.2 * 100).toFixed(0) + '{a|%}',
            textStyle: {
                fontSize: 12,
                fontFamily: 'Microsoft Yahei',
                fontWeight: 'normal',
                color: '#bcb8fb',
                rich: {
                    a: {
                        fontSize: 10,
                    }
                }
            },
            x: 'center',
            y: '35%'
        },
        backgroundColor: '#060646',
        // 数据
        series: [{
            type: 'liquidFill',
            radius: '40%',
            center: ['50%', '50%'],
            data: [0.6, 0.6, 0.6, 0.5],
            backgroundStyle: {
                color: {
                    type: 'radial',
                    x: 0.5,
                    y: 0.5,
                    r: 0.5,
                    colorStops: [{
                        offset: 0,
                        color: 'rgba(255, 255, 0, 0)' // 0% 处的颜色
                    }, {
                        offset: 0.5,
                        color: 'rgba(255, 255, 0, 0)' // 0% 处的颜色
                    }, {
                        offset: 1,
                        color: '#00ffff8c' // 100% 处的颜色
                    }],
                    globalCoord: false // 缺省为 false
                }
            },
            outline: {
                borderDistance: 2,
                itemStyle: {
                    borderWidth: 0,
                    borderColor: {
                        type: 'linear',
                        x: 0,
                        y: 0,
                        x2: 0,
                        y2: 1,
                        colorStops: [{
                            offset: 0,
                            color: 'rgba(69, 73, 240, 0)'
                        }, {
                            offset: 1,
                            color: 'rgba(69, 73, 240, 1)'
                        }],
                        // globalCoord: false
                    },
                    shadowBlur: 30,
                    shadowColor: 'red',
                }
            },
            label: {
                formatter: function() {
                    return '';
                },
            }
        }]
    }
    echarts.init(document.getElementById('container')).setOption(options);
</script>

</html>

胶囊图:

<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>柱状图峰值</title>

    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        html,
        body {
            width: 100%;
            height: 100%;
        }
        
        #container {
            width: 400px;
            height: 400px;
        }
    </style>
</head>

<body>
    <div id="container"></div>
    <script src="https://cdn.bootcss.com/echarts/4.7.0/echarts-en.min.js"></script>
    <script>
        const options = {
            color: ['#003366', '#006699', '#4cabce', '#e5323e'],
            // tooltip: {
            //     trigger: 'axis',
            //     axisPointer: {
            //         type: 'shadow'
            //     }
            // },
            grid: {
                top: '15%'
            },
            toolbox: {
                show: true,
                orient: 'vertical',
                left: 'right',
                top: 'center',
                feature: {
                    mark: {
                        show: true
                    },
                    dataView: {
                        show: true,
                        readOnly: false
                    },
                    magicType: {
                        show: true,
                        type: ['line', 'bar', 'stack', 'tiled']
                    },
                    restore: {
                        show: true
                    },
                    saveAsImage: {
                        show: true
                    }
                }
            },
            backgroundColor: 'rgb(20,28,52)',
            xAxis: [{
                    type: 'category',
                    show: false,
                    axisTick: {
                        show: false
                    },
                    data: ['2012', '2013', '2014', '2015', '2016']
                },
                // 峰值
                {
                    type: 'category',
                    axisTick: {
                        show: false
                    },
                    axisLine: {
                        show: false
                    },
                    axisLabel: {
                        color: 'white',
                        fontSize: 8,
                        formatter: function(value) {
                            if (value == 390) {
                                return '{a|' + value + '}';
                            } else {
                                return value.toLocaleString();
                            }
                        },
                        rich: {
                            a: {
                                fontSize: 12,
                                fontFamily: 'Microsoft YaHei',
                                borderColor: 'red',
                                color: 'red'
                            },
                        },
                    },
                    zlevel: 8,
                    position: 'top',
                    data: [320, 332, 301, 334, 390]
                }
            ],
            yAxis: [{
                type: 'value',
                max: 450,
                show: false
            }],
            series: [{
                name: 'Forest',
                type: 'bar',
                barGap: 0,
                zlevel: 1,
                data: [320, 332, 301, 334, 390],
                itemStyle: {
                    normal: {
                        barBorderRadius: 30,
                        color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                            offset: 0,
                            color: 'rgb(57,89,255,1)'
                        }, {
                            offset: 1,
                            color: 'rgb(46,200,207,1)'
                        }]),
                    },
                },
                barWidth: 20,
                // label:{
                //     normal: {
                //         show: true,
                //         position: 'top'
                //     }
                // }
            }, {
                name: 'Steppe',
                type: 'bar',
                barGap: '-100%',
                itemStyle: {
                    normal: {
                        color: 'rgba(24,31,68,1)',
                        barBorderRadius: 30,
                    }
                },
                barWidth: 20,
                data: [450, 450, 450, 450, 450]
            }, ]
        }
        echarts.init(document.getElementById('container')).setOption(options);
    </script>

</html>

 

水球图效果:

胶囊图效果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

杀猪刀-墨林

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值