echarts实现象形图记录一下

 

    init() {

            let data_X = ["1年以内", "1-3年", "3-7年", "7年以上"];

            let data_Y = [21, 86, 50, 21];

            this.crawPie(this.$refs.MainPopulation_chart, data_X, data_Y);

        },

      crawPie(dom, data_X, data_Y) {

            let myChart =

                this.$echarts.getInstanceByDom(dom) || this.$echarts.init(dom);

            myChart.setOption({

                grid: {

                    top: "15%",

                    bottom: "20%",

                    left: "3%",

                    right: "3%",

                },

                xAxis: {

                    data: data_X,

                    axisTick: {

                        show: false,

                    },

                    axisLine: {

                        show: false,

                    },

                    axisLabel: {

                        show: true,

                        interval: 0,

                        margin: 25,

                        align: "center",

                        textStyle: {

                            fontSize: 12,

                            color: "#ffffff",

                            fontWeight: 600,

                        },

                    },

                },

                yAxis: {

                    splitLine: {

                        show: false,

                    },

                    axisTick: {

                        show: false,

                    },

                    axisLine: {

                        show: false,

                    },

                    axisLabel: {

                        show: false,

                    },

                },

                series: [

                    {

                        name: "顶部黑色点",

                        type: "pictorialBar",

                        symbol: "circle",

                        symbolRepeat: false,

                        barWidth: 14,

                        symbolSize: [4, 4],

                        symbolOffset: [5, 8],

                        z: 14,

                        itemStyle: {

                            normal: {

                                color: function (params) {

                                    return "black";

                                },

                            },

                        },

                        symbolPosition: "end",

                        data: (function () {

                            let _data = data_Y.map(function (i) {

                                return i + 30;

                            });

                            return _data;

                        })(),

                    },

                    {

                        name: "顶部黄色点",

                        type: "pictorialBar",

                        symbol: "circle",

                        symbolRepeat: false,

                        barWidth: 14,

                        symbolSize: [12, 12],

                        symbolOffset: [5, 5],

                        z: 13,

                        itemStyle: {

                            normal: {

                                color: function (params) {

                                    return "orange";

                                },

                            },

                        },

                        symbolPosition: "end",

                        data: (function () {

                            let _data = data_Y.map(function (i) {

                                return i + 30;

                            });

                            return _data;

                        })(),

                    },

                    {

                        name: "顶部上",

                        type: "pictorialBar",

                        symbol: "rect",

                        symbolRepeat: false,

                        barWidth: 14,

                        symbolOffset: [5, 5],

                        z: 12,

                        itemStyle: {

                            normal: {

                                color: function (params) {

                                    return "red";

                                },

                                opacity: 0.2,

                            },

                        },

                        symbolPosition: "end",

                        data: (function () {

                            let _data = data_Y.map(function (i) {

                                return i + 30;

                            });

                            return _data;

                        })(),

                    },

                    {

                        name: "柱顶部",

                        type: "pictorialBar",

                        symbolSize: [26, 10],

                        symbolOffset: [0, -5],

                        z: 18,

                        itemStyle: {

                            normal: {

                                color: function (params) {

                                    return "#42DDFC";

                                },

                            },

                        },

                        label: {

                            show: true,

                            position: "top",

                            fontSize: 12,

                            color: "#FFFF00",

                            fontFamily: "tenxu",

                            formatter: "{c}%",

                        },

                        symbolPosition: "end",

                        data: data_Y,

                    },

                    {

                        name: "柱底部",

                        type: "pictorialBar",

                        symbolSize: [26, 10],

                        symbolOffset: [0, 5],

                        z: 17,

                        itemStyle: {

                            normal: {

                                color: function (params) {

                                    return "#42DDFC";

                                },

                            },

                        },

                        data: data_Y,

                    },

                    {

                        name: "第一圈",

                        type: "pictorialBar",

                        symbolSize: [40, 15],

                        symbolOffset: [0, 13],

                        z: 11,

                        itemStyle: {

                            normal: {

                                color: function (params) {

                                    return "#07344D";

                                },

                            },

                        },

                        data: data_Y,

                    },

                    {

                        name: "第二圈",

                        type: "pictorialBar",

                        symbolSize: [42, 20],

                        symbolOffset: [0, 15],

                        z: 10,

                        itemStyle: {

                            normal: {

                                color: function (params) {

                                    return "#40ECFE";

                                },

                            },

                        },

                        data: data_Y,

                    },

                    {

                        type: "bar",

                        itemStyle: {

                            normal: {

                                // 中间柱子渐变色

                                color: function (params) {

                                    return {

                                        type: "linear",

                                        x: 0,

                                        y: 0,

                                        x2: 1,

                                        y2: 0,

                                        colorStops: [

                                            {

                                                offset: 1,

                                                color: "#149ECD",

                                            },

                                            {

                                                offset: 0,

                                                color: "#36E8F2",

                                            },

                                        ],

                                        global: false,

                                    };

                                },

                            },

                        },

                        z: 16,

                        silent: true,

                        barWidth: 26,

                        barGap: "-100%", // Make series be overlap

                        data: data_Y,

                    },

                ],

            });

            window.addEventListener("resize", function () {

                myChart.resize();

            });

        },

浅浅记录一下

 参考链接:Echarts 象形柱状图(pictorialBar)-pudn.com

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值