echarts特殊柱状图

237 阅读3分钟

“我正在参加「掘金·启航计划」”

学习过程中将笔记跟大家分享,希望对大家也有所帮助,共同成长进步💪~
如果大家喜欢,可以点赞或留言💕~~~~,谢谢大家⭐️⭐️⭐️~~~

效果图:

image.png

代码如下:

myChart1() {
    var chart1 = echarts.init(document.querySelector('#myChart1'));
    let xData = ['火电', '水电', '风电', '光伏', '煤炭', '化工', '运输'],
        yData = [100, 120, 130, 150, 90, 140, 160],
        barData = ['30', '20', '10', '40', '25', '35', '45'];
    color = ['rgba(32, 130, 239, 0.78)', 'rgba(84, 94, 192, 0.3)'];
    chart1Option = {
        grid: {
            top: '15%',
            left: '5%',
            bottom: '15%',
            right: '5%',
            containLabel: true,
        },
        color:['rgba(32, 130, 239, 0.9)', 'rgba(84, 94, 192, 0.3)'],
        legend: {
            data: ['合同总金额', '结算金额'],
            itemWidth: 14,
            itemHeight: 8,
            bottom: 0,
            left: 'center',
            color: ['rgba(32, 130, 239, 0.78)', 'rgba(84, 94, 192, 0.3)'],
            itemStyle: {

            },
            textStyle: {
                color: '#A1ECFF',
                fontSize: 12,
                fontWeight: 400
            }
        },
        tooltip: {
            trigger: 'item',
        },
        animation: false,
        xAxis: [
            {
                type: 'category',
                data: xData,
                axisTick: {
                    alignWithLabel: true,
                },
                axisLine: {
                    show: true,
                    lineStyle: {
                        color: '#0C4F81',
                        type: 'dashed',
                        width: 1,
                    }
                },
                axisLabel: {
                    textStyle: {
                        color: '#fff',
                        fontSize: 14,
                        fontWeight: 400,
                    },
                    margin: 30,
                },
                interval: 1,
            },
        ],
        yAxis: [
            {
                show: true,
                type: 'value',
                axisLine: {
                    show: true,
                    lineStyle: {
                        color: '#0C4F81',
                        type: 'solid',
                        width: 1,
                    }
                },
                axisLabel: {
                    show: true,
                    textStyle: {
                        color: '#4F88BD',
                        fontSize: 12,
                        fontWight: 400

                    }
                },
                splitLine: {
                    show: true,
                    lineStyle: {
                        color: '#0C4F81',
                        type: 'dashed',
                        width: 1,
                    }
                }
            },
        ],
        series: [
            {
                name: '上部圆',
                type: 'pictorialBar',
                silent: true,
                symbolSize: [40, 10],
                symbolOffset: [0, -6],
                symbolPosition: 'end',
                z: 12,
                label: {
                    normal: {
                        show: true,
                        position: 'top',
                        fontSize: 12,
                        fontWeight: 400,
                        color: '#fff',
                    },
                },
                color: new echarts.graphic.LinearGradient(0, 0, 0, 0.7, [
                    {
                        offset: 0,
                        color: 'rgba(55, 130, 211, .5)',
                    },
                    {
                        offset: 1,
                        color: 'rgba(55, 130, 211, .5)',
                    },
                ]),
                data: yData,
            },
            {
                name: '底部圆',
                type: 'pictorialBar',
                silent: true,
                symbolSize: [40, 10],
                symbolOffset: [0, 7],
                z: 12,
                color: new echarts.graphic.LinearGradient(0, 0, 0, 0.7, [
                    {
                        offset: 0,
                        color: 'rgba(105, 118, 246, 0.7)',
                    },
                    {
                        offset: 1,
                        color: 'rgba(105, 118, 246, 0.01)',
                    },
                ]),
                data: yData,
            },


            {
                name: '合同总金额',
                type: 'bar',
                barWidth: '40',
                barGap: '10%', // Make series be overlap
                barCateGoryGap: '10%',
                itemStyle: {
                    normal: {
                        color: new echarts.graphic.LinearGradient(0, 0, 0, 0.7, [
                            {
                                offset: 0,
                                color: 'rgba(32, 130, 239, .3)',
                            },
                            {
                                offset: 1,
                                color: 'rgba(32, 130, 239, .3)',
                            },
                        ]),
                        opacity: 0.8,
                    },
                },
                data: yData,
            },
            {
                name: '结算金额',
                type: 'bar',
                barWidth: 40,
                z: 12,
                barGap: '-100%',
                itemStyle: {
                    //lenged文本
                    opacity: 0.7,
                    color: function (params) {
                        return new echarts.graphic.LinearGradient(
                            0,
                            0,
                            0,
                            1,
                            [
                                {
                                    offset: 0,
                                    color: 'rgba(32, 130, 239, 0.9)', // 0% 处的颜色
                                },
                                {
                                    offset: 1,
                                    color: 'rgba(84, 94, 192, 0.5)', // 100% 处的颜色
                                },

                            ],
                            false
                        );
                    },
                },

                data: barData,
            },
            {
                name: '上部圆',
                type: 'pictorialBar',
                silent: true,
                symbolSize: [40, 10],
                symbolOffset: [0, -6],
                symbolPosition: 'end',
                z: 12,
                color: '#3782D3',
                data: barData,
                label: {
                    // normal: {
                        show: true,
                        position: 'inside',
                        fontSize: 18,
                        fontWeight: 'bold',
                        fontFamily: 'DS-Digital',
                        color: '#E5F8FC',
                        formatter: '{c}%'
                    // },
                },
            },
            {
                name: '底部圆',
                type: 'pictorialBar',
                silent: true,
                symbolSize: [40, 10],
                symbolOffset: [0, 7],
                z: 12,
                color: new echarts.graphic.LinearGradient(0, 0, 0, 0.7, [
                    {
                        offset: 0,
                        color: 'rgba(105, 118, 246, 0.1)',
                    },
                    {
                        offset: 1,
                        color: 'rgba(105, 118, 246, 0.7)',
                    },
                ]),
                data: barData,
            },
        ],
};

感谢大家阅读⭐️⭐️⭐️,如果喜欢,可以点赞或留言哟💕💕💕
后续会持续更新记录😊~~~

近期热门文章

专栏推荐

推荐一下自己的专栏,欢迎大家收藏关注😊~