2021-11-10

echarts 画伪3D柱状图

1. 效果
在这里插入图片描述
2. 代码

var value = 0;
var colors = [
    {
        type: 'linear',
        x: 0,
        x2: 0,
        y: 0,
        y2: 1,
        colorStops: [
            {
                offset: 0,
                color: '#30a4cf',
            },
            {
                offset: 1,
                color: '#3070cf',
            },
        ],
    },
    {
        type: 'linear',
        x: 0,
        x2: 0,
        y: 0,
        y2: 1,
        colorStops: [
            {
                offset: 0,
                color: '#78cc40',
            },
            {
                offset: 1,
                color: '#2fd28d',
            },
        ],
    },
    {
        type: 'linear',
        x: 0,
        x2: 0,
        y: 0,
        y2: 1,
        colorStops: [
            {
                offset: 0,
                color: '#f5a43a',
            },
            {
                offset: 1,
                color: '#c4742d',
            },
        ],
    },
    {
        type: 'linear',
        x: 0,
        x2: 0,
        y: 0,
        y2: 1,
        colorStops: [
            {
                offset: 0,
                color: 'rgba(245,89,58,0.78)',
            },
            {
                offset: 1,
                color: 'rgba(196,45,45,1)',
            },
        ],
    },
    {
        type: 'linear',
        x: 0,
        x2: 0,
        y: 0,
        y2: 1,
        colorStops: [
            {
                offset: 0,
                color: '#f5593a',
            },
            {
                offset: 1,
                color: '#c42d2d',
            },
        ],
    },
];
var maxData = 300;
var redData = 270;
var orangeData = 260;
var yellowData = 240;
var datas =''
if (value ===0) {
    datas=0.1
}else {
    datas=value
}
option = {
    backgroundColor: '#0e202d',

    grid: {
        top: 240,
        bottom: 150,
        right: '55%',
    },
    // tooltip: {},
    xAxis: {
        data: [],
        axisTick: {
            show: false,
        },
        axisLine: {
            show: false,
        },
        // axisLabel: {
        //     interval: 0,
        //     textStyle: {
        //         color: '#beceff',
        //         fontSize: 20,
        //     },
        //     margin: 80, //刻度标签与轴线之间的距离。
        // },
    },
    yAxis: {
        show: true,
        splitNumber: 4,
        axisLine: {
            show: true,
            lineStyle: {
                color: '#80D4FF',
            },
        },
        splitLine: {
            show: false,
        },
        axisLabel: {
            color: '#FFFFFF',
        },
        axisTick: {
            show: true,
        },
    },
    series: [
        {
            name: '',
            type: 'pictorialBar',
            symbolSize: [200, 45],
            symbolOffset: [-10, -20],
            z: 13,
            data: [
                {
                    name: '',
                    value: value,
                    symbolPosition: 'end',
                    itemStyle: {
                        normal: {
                            borderColor:'#438FC2',
                            color: 'RGBA(40, 91, 134, .8)' //圆柱顶部颜色
                        },
                    },
                },
            ],
        },
        {
            name: '',
            type: 'pictorialBar',
            animation: false,
            symbolSize: [200, 45],
            symbolOffset: [-10, 24],
            z: 11,
            data: [
                {
                    name: '',
                    value: datas,
                    itemStyle: {
                        normal: {
                            borderWidth: 1,
                            color: 'RGBA(62, 140, 218, 1)',
                            // color: 'RGBA(40, 91, 134, 1)',
                            borderColor: '#418DBA',
                        },
                    },
                },
            ],
        },
        // 内部柱子
        {
            type: 'bar',
            // silent: true,
            barWidth: 200,
            // "barGap": "-1100%",

            data: [
                {
                    name: '',
                    value: value,

                    label: {
                        normal: {
                            show: true,
                            // formatter: '{c}',
                            position: 'top',
                            distance: 24,
                            textStyle: {
                                color: '#fff', //柱子对应数值颜色
                                fontSize: 18,
                            },
                        },
                    },
                    itemStyle: {
                        normal: {
                            color: {
                                x: 0,
                                y: 0,
                                x2: 0,
                                y2: 1,
                                type: 'linear',
                                global: false,
                                colorStops: [
                                    {
                                        offset: 0,
                                        color: 'RGBA(47, 116, 173, 1)',
                                    },
                                    {
                                        offset: 1,
                                        color: 'RGBA(64, 146, 222, 1)', //底部渐变颜色
                                    },
                                ],
                            },
                        },
                    },
                },
            ],
        },

        //往上是内部柱状图
        //往下是外部柱状图

        {
            name: '',
            type: 'pictorialBar',
            animation: false,
            symbolSize: [240, 45],
            symbolOffset: [-10, -20],
            z: 12,
            data: [
                {
                    name: '',
                    value: maxData,

                    symbolPosition: 'end',
                    itemStyle: {
                        normal: {
                            color: 'RGBA(40, 69, 147, .6)',
              borderColor: '#4674BF' //圆柱顶部颜色
                        },
                    },
                },
            ],
        },
        // 红色预警
        {
            name: '',
            type: 'pictorialBar',
            animation: false,
            symbolSize: [240, 45],
            symbolOffset: [-10, 0],
            z: 12,
            data: [
                {
                    name: '',
                    value: redData,

                    symbolPosition: 'end',
                    itemStyle: {
                        normal: {
                            color: '#443349',
                            borderColor: '#F42626',
                            borderWidth: 1,
                        },
                    },
                    label: {
                        show: true,
                        position: 'insideTop',
                        distance: 10, //20%位置
                        rich: {
                            a: {
                                color: '#F42626',
                                fontSize: 14,
                                align: 'left',
                                padding: [0, 0, 0, 270],
                                width: 40,
                                height: 16,
                                lineHeight: 16,
                            },
                        },
                        formatter: (params) => {
                            return '{a|' + '红色预警}';
                        },
                    },
                },
            ],
        },
        // 橙色预警
        {
            name: '',
            type: 'pictorialBar',
            animation: false,
            symbolSize: [240, 45],
            symbolOffset: [-10, 0],
            z: 11,
            data: [
                {
                    name: '',
                    value: orangeData,

                    symbolPosition: 'end',
                    itemStyle: {
                        normal: {
                            color: '#3F4744',
                            borderColor: '#FC9F44',
                            borderWidth: 1,
                        },
                    },
                    label: {
                        show: true,
                        position: 'insideTop',
                        distance: 15, //20%位置
                        rich: {
                            a: {
                                color: '#FC9F44',
                                fontSize: 14,
                                align: 'left',
                                padding: [0, 0, 0, 270],
                                width: 40,
                                height: 16,
                                lineHeight: 16,
                            },
                        },
                        formatter: (params) => {
                            return '{a|' + '橙色预警}';
                        },
                    },
                },
            ],
        },
        // 黄色预警
        {
            name: '',
            type: 'pictorialBar',
            animation: false,
            symbolSize: [240, 45],
            symbolOffset: [-10, 0],
            z: 10,
            data: [
                {
                    name: '',
                    value: yellowData,

                    symbolPosition: 'end',
                    itemStyle: {
                        normal: {
                            color: '#425A45',
                            borderColor: '#FFCD1F',
                            borderWidth: 1,
                        },
                    },
                    label: {
                        show: true,
                        position: 'insideTop',
                        distance: 20, //20%位置
                        rich: {
                            a: {
                                color: '#FFCD1F',
                                fontSize: 14,
                                align: 'left',
                                padding: [0, 0, 0, 270],
                                width: 40,
                                height: 16,
                                lineHeight: 16,
                            },
                        },
                        formatter: (params) => {
                            return '{a|' + '黄色预警}';
                        },
                    },
                },
            ],
        },
        {
            name: '',
            type: 'pictorialBar',
            animation: false,
            symbolSize: [240, 75],
            symbolOffset: [-10, 41],
            z: 12,
            data: [
                {
                    name: '',
                    value: maxData,

                    itemStyle: {
                        normal: {
                            color: 'transparent',
              borderColor: 'rgba(0,255,252,0.4)' //圆柱底部颜色
                        },
                    },
                },
            ],
        },
        //   外部柱子
        {
            type: 'bar',
            silent: true,
            barWidth: 240,
            animation: false,
            barGap: '-110%',
            data: [
                {
                    name: '',
                    value: maxData,

                    label: {
                        normal: {
                            show: false,
                        },
                    },
                    itemStyle: {
                        normal: {
                             color: 'RGBA(21, 58, 93, .3)'
                        },
                    },
                },
            ],
        },
    ],
};

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Ciito

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

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

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

打赏作者

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

抵扣说明:

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

余额充值