echarts 自定义柱状图 bar,effectScatter,pictorialBar

效果、代码如下在这里插入图片描述

<template>
<div style=" width: 1131px; height: 620px; " ref="myChart"></div>
</template>
<script>
import * as echarts from 'echarts'

    export default {
        data() {
            return {
           
            }
        },
      mounted() {
        let myChart = echarts.init(this.$refs.myChart)
        this.initChart(myChart,echarts)
      },
      methods: {

            initChart(myChart, echarts) {
                var option = {}
                let v2L2Chart = {
                    xData: ['2019年', '2020年', '2021年', '2022年'],
                    data: [212, 305, 260, 283],
                    max: 500,
                    color: ['rgba(253, 221, 97,  1)', 'rgba(107, 255, 243,  1)', 'rgba(119, 191, 255, 1)', 'rgba(0, 72, 203,1)', ]
                };
                option = {
                    backgroundColor: '#000',
                    grid: {
                        top: '5%',
                        left: '10%',
                        right: '9%',
                        bottom: '40%',
                    },
                    tooltip: {
                        show: true,
                        formatter: function(params) {
                            let text = '<p  style="font-size:16px;font-weight: 400;color:rgba(255, 255, 255, 1);margin-bottom: 20px;"><span style="display:inline-block;width:10px;height: 10px;background: ' + v2L2Chart.color[params.dataIndex] + ';border-radius: 50%;margin-right: 10px;"></span>' + v2L2Chart.xData[params.dataIndex] + ':' + v2L2Chart.data[params.dataIndex] + '个</p>';
                            return text
                        },
                        // formatter: (params) => {
                        //     return v2L2Chart.xData[params.dataIndex] + ':' + v2L2Chart.data[params.dataIndex] + '个';

                        // },
                        backgroundColor: 'rgba(38, 68, 110, 0.8)',
                        padding: 10,
                        borderColor: 'rgba(38, 68, 110, 1)',
                        textStyle: {
                            color: '#fff',
                        }
                    },

                    xAxis: {
                        offset: 20,
                        data: v2L2Chart.xData,
                        axisTick: {
                            show: false,
                        },
                        axisLine: {
                            show: false,
                        },
                        axisLabel: {
                            textStyle: {
                                color: '#fff',
                                fontSize: 16,
                            },
                        },
                    },
                    yAxis: {
                        splitLine: {
                            show: false,
                        },
                        axisTick: {
                            show: false,
                        },
                        axisLine: {
                            show: false,
                        },
                        axisLabel: {
                            show: false,
                        },
                    },
                    series: [
                        //'最低下的圆片',
                        {
                            name: '最低下的圆片',
                            stack: 'a',
                            // type: 'pictorialBar',
                            // symbolSize: [66, 12],
                            // symbolOffset: [0, 6],
                            type: 'effectScatter',
                            symbolSize: [62, 12],
                            symbolOffset: [0, 0],
                            z: 22,
                            data: [{
                                    name: '',
                                    value: '0',
                                    itemStyle: {
                                        normal: {
                                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                                    offset: 0,
                                                    color: 'rgba(253, 221, 97,  1)',
                                                },
                                                {
                                                    offset: 1,
                                                    color: 'rgba(251, 171, 88,   1)',
                                                },
                                            ]),
                                        },
                                    },
                                },
                                {
                                    name: '',
                                    value: '0',
                                    itemStyle: {
                                        normal: {
                                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                                    offset: 0,
                                                    color: 'rgba(107, 255, 243,  1)',
                                                },
                                                {
                                                    offset: 1,
                                                    color: 'rgba(8, 177, 255, 1)',
                                                },
                                            ]),
                                        },
                                    },
                                },
                                {
                                    name: '',
                                    value: '0',
                                    itemStyle: {
                                        normal: {
                                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                                    offset: 0,
                                                    color: 'rgba(119, 191, 255, 1)',
                                                },
                                                {
                                                    offset: 1,
                                                    color: 'rgba(102, 155, 255, 1)',
                                                },
                                            ]),
                                        },
                                    },
                                },
                                {
                                    name: '',
                                    value: '0',
                                    itemStyle: {
                                        normal: {
                                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                                    offset: 0,
                                                    color: 'rgba(14, 195, 255, 1)',
                                                },
                                                {
                                                    offset: 1,
                                                    color: 'rgba(0, 72, 203,  1)',
                                                },
                                            ]),
                                        },
                                    },
                                },
                            ],
                        },
                        //下半截柱状图
                        {
                            name: '下半截柱状图',
                            stack: 'a',
                            type: 'bar',
                            barWidth: 66,
                            z: 2,
                            barGap: '-100%',
                            data: [{
                                    name: '',
                                    value: '212',
                                    itemStyle: {
                                        normal: {
                                            color: {
                                                x: 0,
                                                y: 0,
                                                x2: 0,
                                                y2: 1,
                                                type: 'linear',
                                                global: false,
                                                colorStops: [{
                                                        //第一节下面
                                                        offset: 0,
                                                        color: 'rgba(251, 171, 88, 0.8)',
                                                    },
                                                    {
                                                        offset: 1,
                                                        color: 'rgba(253, 227, 100,0.8)',
                                                    },
                                                ],
                                            },
                                        },
                                    },
                                },
                                {
                                    name: '',
                                    value: '305',
                                    itemStyle: {
                                        normal: {
                                            color: {
                                                x: 0,
                                                y: 0,
                                                x2: 0,
                                                y2: 1,
                                                type: 'linear',
                                                global: false,
                                                colorStops: [{
                                                        //第二个柱状图下面

                                                        offset: 0,
                                                        color: 'rgba(8, 177, 255, 0.8)',
                                                    },
                                                    {
                                                        offset: 1,
                                                        color: 'rgba(107, 255, 243, 0.8)',
                                                    },
                                                ],
                                            },
                                        },
                                    },
                                },
                                {
                                    name: '',
                                    value: '260',
                                    itemStyle: {
                                        normal: {
                                            color: {
                                                x: 0,
                                                y: 0,
                                                x2: 0,
                                                y2: 1,
                                                type: 'linear',
                                                global: false,
                                                colorStops: [{
                                                        //第三个柱状图下半截
                                                        offset: 0,
                                                        color: 'rgba(119, 191, 255, 0.8)',
                                                    },
                                                    {
                                                        offset: 1,
                                                        color: 'rgba(102, 155, 255, 0.8)',
                                                    },
                                                ],
                                            },
                                        },
                                    },
                                },
                                {
                                    name: '',
                                    value: '283',
                                    itemStyle: {
                                        normal: {
                                            color: {
                                                x: 0,
                                                y: 0,
                                                x2: 0,
                                                y2: 1,
                                                type: 'linear',
                                                global: false,
                                                colorStops: [{
                                                        //第三个柱状图下半截
                                                        offset: 0,
                                                        color: 'rgba(0, 72, 203,0.8)',
                                                    },
                                                    {
                                                        offset: 1,
                                                        color: 'rgba(14, 195, 255, 0.8)',
                                                    },
                                                ],
                                            },
                                        },
                                    },
                                },
                            ],
                        },
                        //替代柱状图 默认不显示颜色,是最下方柱图的value值 - 20'
                        {
                            name: '替代柱状图 默认不显示颜色,是最下方柱图的value值 - 20',
                            // stack: 'a',
                            type: 'bar',
                            barWidth: 66,
                            barGap: '-100%',
                            stack: '广告',
                            itemStyle: {
                                color: 'transparent',
                            },
                            data: [212, 305, 260, 283],
                        },
                        //头部1
                        {
                            name: '头部1',
                            stack: 'a',
                            type: 'pictorialBar',
                            symbolSize: [66, 12],
                            symbolOffset: [0, -6],
                            z: 22,
                            data: [
                                {
                                    name: '',
                                    value: '212',
                                    symbolPosition: 'end',
                                    label: {
                                        formatter: '{c} 个',
                                        color: '#fff',
                                        offset: [0, -5],
                                        show: true,
                                        position: 'top',
                                        fontSize: 18,
                                        fontWeight: 400,
                                        fontFamily: 'zcool-gdh',
                                    },
                                    itemStyle: {
                                        normal: {
                                            color: new echarts.graphic.LinearGradient(
                                                0,
                                                0,
                                                0,
                                                1,
                                                [{
                                                        offset: 0,
                                                        color: 'rgba(251, 171, 88, 1)',
                                                    },
                                                    {
                                                        offset: 1,
                                                        color: 'rgba(253, 227, 100,  1)',
                                                    },
                                                ],
                                                false
                                            ),
                                        },
                                    },
                                },
                                {
                                    name: '',
                                    value: '305',
                                    symbolPosition: 'end',
                                    label: {
                                        formatter: '{c} 个',
                                        color: '#fff',
                                        offset: [0, -5],
                                        show: true,
                                        position: 'top',
                                        fontSize: 18,
                                        fontWeight: 400,
                                        fontFamily: 'zcool-gdh',
                                    },
                                    itemStyle: {
                                        normal: {
                                            color: new echarts.graphic.LinearGradient(
                                                0,
                                                0,
                                                0,
                                                1,
                                                [{
                                                        offset: 0,
                                                        color: 'rgba(8, 177, 255,   1)',
                                                    },
                                                    {
                                                        offset: 1,
                                                        color: 'rgba(107, 255, 243,    1)',
                                                    },
                                                ],
                                                false
                                            ),
                                        },
                                    },
                                },
                                {
                                    name: '',
                                    value: '260',
                                    symbolPosition: 'end',
                                    label: {
                                        formatter: '{c} 个',
                                        color: '#fff',
                                        offset: [0, -5],
                                        show: true,
                                        position: 'top',
                                        fontSize: 18,
                                        fontWeight: 400,
                                        fontFamily: 'zcool-gdh',
                                    },
                                    itemStyle: {
                                        normal: {
                                            color: new echarts.graphic.LinearGradient(
                                                0,
                                                0,
                                                0,
                                                1,
                                                [{
                                                        offset: 0,
                                                        color: 'rgba(119, 191, 255,  1)',
                                                    },
                                                    {
                                                        offset: 1,
                                                        color: 'rgba(102, 155, 255,    1)',
                                                    },
                                                ],
                                                false
                                            ),
                                        },
                                    },
                                },
                                {
                                    name: '',
                                    value: '283',
                                    symbolPosition: 'end',
                                    label: {
                                        formatter: '{c} 个',
                                        color: '#fff',
                                        offset: [0, -5],
                                        show: true,
                                        position: 'top',
                                        fontSize: 18,
                                        fontWeight: 400,
                                        fontFamily: 'zcool-gdh',
                                    },
                                    itemStyle: {
                                        normal: {
                                            color: new echarts.graphic.LinearGradient(
                                                0,
                                                0,
                                                0,
                                                1,
                                                [{
                                                        offset: 0,
                                                        color: 'rgba(0, 72, 203,  1)',
                                                    },
                                                    {
                                                        offset: 1,
                                                        color: 'rgba(14, 195, 255,  1)',
                                                    },
                                                ],
                                                false
                                            ),
                                        },
                                    },
                                },
                            ],
                        },
                        //头部2
                        {
                            name: '头部2',
                            stack: 'a',
                            type: 'pictorialBar',
                            symbolSize: [66, 12],
                            symbolOffset: [0, -6],
                            z: 22,
                            data: [
                                {
                                    name: '',
                                    value: v2L2Chart.max,
                                    symbolPosition: 'end',
                                    itemStyle: {
                                        normal: {
                                            color: {
                                                type: 'radial',
                                                x: 0.5,
                                                y: 0.6,
                                                r: 0.5,
                                                colorStops: [{
                                                        offset: 0,
                                                        color: 'rgba(253, 224, 99, 0.8)', // 0% 处的颜色
                                                    },
                                                    {
                                                        offset: 0.4,
                                                        color: 'rgba(253, 224, 99, 0.8)', // 0% 处的颜色
                                                    },
                                                    {
                                                        offset: 1,
                                                        color: 'rgba(253, 179, 88, 0.6)', // 100% 处的颜色
                                                    },
                                                ],
                                                globalCoord: false, // 缺省为 false
                                            },
                                        },
                                    },
                                },
                                {
                                    name: '',
                                    value: v2L2Chart.max,
                                    symbolPosition: 'end',
                                    itemStyle: {
                                        normal: {
                                            color: {
                                                type: 'radial',
                                                x: 0.5,
                                                y: 0.6,
                                                r: 0.5,
                                                colorStops: [{
                                                        offset: 0,
                                                        color: 'rgba(31, 194, 252, 0.8)', // 0% 处的颜色
                                                    },
                                                    {
                                                        offset: 0.4,
                                                        color: 'rgba(31, 194, 252, 0.8)', // 0% 处的颜色
                                                    },
                                                    {
                                                        offset: 1,
                                                        color: 'rgba(31, 194, 252, 0.6)', // 100% 处的颜色
                                                    },
                                                ],
                                                globalCoord: false, // 缺省为 false
                                            },
                                        },
                                    },
                                },
                                {
                                    name: '',
                                    value: v2L2Chart.max,
                                    symbolPosition: 'end',
                                    itemStyle: {
                                        normal: {
                                            color: {
                                                type: 'radial',
                                                x: 0.5,
                                                y: 0.6,
                                                r: 0.5,
                                                colorStops: [{
                                                        offset: 0,
                                                        color: 'rgba(115, 182, 255, 0.8)', // 0% 处的颜色
                                                    },
                                                    {
                                                        offset: 0.4,
                                                        color: 'rgba(115, 182, 255, 0.8)', // 0% 处的颜色
                                                    },
                                                    {
                                                        offset: 1,
                                                        color: 'rgba(115, 182, 255, 0.6)', // 100% 处的颜色
                                                    },
                                                ],
                                                globalCoord: false, // 缺省为 false
                                            },
                                        },
                                    },
                                },
                                {
                                    name: '',
                                    value: v2L2Chart.max,
                                    symbolPosition: 'end',
                                    itemStyle: {
                                        normal: {
                                            color: {
                                                type: 'radial',
                                                x: 0.5,
                                                y: 0.6,
                                                r: 0.5,
                                                colorStops: [{
                                                        offset: 0,
                                                        color: 'rgba(1, 80, 207, 0.8)', // 0% 处的颜色
                                                    },
                                                    {
                                                        offset: 0.4,
                                                        color: 'rgba(1, 80, 207, 0.8)', // 0% 处的颜色
                                                    },
                                                    {
                                                        offset: 1,
                                                        color: 'rgba(1, 80, 207, 0.6)', // 100% 处的颜色
                                                    },
                                                ],
                                                globalCoord: false, // 缺省为 false
                                            },
                                        },
                                    },
                                },
                            ],
                        },
                        //底色
                        {
                            name: '底色',
                            // stack: 'a',
                            type: 'bar',
                            barWidth: 66,
                            z: 2,
                            barGap: '-100%',
                            stack: '广告',
                            data: [{
                                    name: '',
                                    value: v2L2Chart.max - v2L2Chart.data[0],
                                    symbolPosition: 'end',
                                    itemStyle: {
                                        normal: {
                                            color: 'rgba(253, 179, 88, 0.4)',
                                        },
                                    },
                                },
                                {
                                    name: '',
                                    value: v2L2Chart.max - v2L2Chart.data[1],
                                    symbolPosition: 'end',
                                    itemStyle: {
                                        normal: {
                                            color: 'rgba(31, 194, 252, 0.4)',
                                        },
                                    },
                                },
                                {
                                    name: '',
                                    value: v2L2Chart.max - v2L2Chart.data[2],
                                    symbolPosition: 'end',
                                    itemStyle: {
                                        normal: {
                                            color: 'rgba(115, 182, 255, 0.4)',
                                        },
                                    },
                                },
                                {
                                    name: '',
                                    value: v2L2Chart.max - v2L2Chart.data[3],
                                    symbolPosition: 'end',
                                    itemStyle: {
                                        normal: {
                                            color: 'rgba(1, 80, 207,  0.4)',
                                        },
                                    },
                                },
                            ],
                        },
                    ],
                };

                myChart.setOption(option, true);
            }
        },
        created() {
            this.created_sys();

        }
    }
</script>
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值