Echarts4象形柱图PictorialBar扩展

代码片段:

var cities = [{

        name: '河北',

        value: 10

    },

    {

        name: '北京',

        value: 14

    },

    {

        name: '上海',

        value: 4

    },

    {

        name: '黑龙江',

        value: 5

    },

    {

        name: '吉林',

        value: 7

    },

    {

        name: '辽宁',

        value: 6

    },

    {

        name: '内蒙古',

        value: 4

    },

    {

        name: '新疆',

        value: 4

    },

    {

        name: '西藏',

        value: 1

    },

    {

        name: '甘肃',

        value: 5

    },

    {

        name: '青海',

        value: 1

    },

    {

        name: '海南',

        value: 0

    },

    {

        name: '天津',

        value: 6

    },

    {

        name: '山西',

        value: 4

    },

    {

        name: '宁夏',

        value: 2

    },

    {

        name: '山东',

        value: 14

    },

    {

        name: '陕西',

        value: 8

    },

    {

        name: '河南',

        value: 14

    },

    {

        name: '江苏',

        value: 21

    },

    {

        name: '安徽',

        value: 7

    },

    {

        name: '湖北',

        value: 9

    },

    {

        name: '四川',

        value: 10

    },

    {

        name: '重庆',

        value: 4

    },

    {

        name: '江西',

        value: 6

    },

    {

        name: '浙江',

        value: 2

    },

    {

        name: '湖南',

        value: 7

    },

    {

        name: '贵州',

        value: 3

    },

    {

        name: '福建',

        value: 6

    },

    {

        name: '云南',

        value: 4

    },

    {

        name: '广西',

        value: 4

    },

    {

        name: '广东',

        value: 8

    },

    {

        name: '香港',

        value: 0

    },

    {

        name: '澳门',

        value: 0

    },

    {

        name: '台湾',

        value: 0

    },

].sort(function(a, b) {

    return b.value - a.value;

});

var labelOption = {

    show: true,

    lineHeight: 20,

    align: 'left',

    position: 'top',

    rich: {

        name: {

            color: '#fff',

            fontSize: 16,

            textShadowBlur: 2,

            textShadowColor: '#000',

            textShadowOffsetX: 0,

            textShadowOffsetY: 1,

            textBorderColor: '#333',

            textBorderWidth: 2

        },

        value: {

            fontSize: 14,

            color: 'rgb(84,184,167)'

        },

        desc: {

            color: 'rgb(85,85,85)',

            textBorderColor: '#000',

            textBorderWidth: 1,

            fontSize: 12

        },

    }

};

var xData = [],

    vData = [],

    lineData = [],

    pointData = [];

cities.forEach(function(city, index) {

    xData.push(city.name);

    vData.push({

        value: city.value,

        //symbol: pathSymbols.run,

        symbol: 'circle',

        symbolSize: 10,

        color:'red',

    });

 

    let coord1 = [index, city.value+0.5];

    let coord2 ;

    if(index===0){

        coord2=[index, city.value+2];

    }else{

        if(city.value===cities[index-1].value){

            coord2=[index, pointData[index-1].coord[1]];

        }else{

            coord2=[index, cities[index-1].value];

        }

 

    }

    pointData.push(Object.assign({}, {

        label: Object.assign({}, labelOption, {

            formatter: [

                '{name|' + city.name + '}\n',

                '{value|' + city.value + '}'

                //'{desc|'+item.data.desc+'}'

            ].join('')

        }),

        coord: coord2

    }))

    lineData.push(

        [{

            xAxis: index,

            coord: coord1

        }, {

            xAxis: index,

            coord: coord2

        }]);

});

var axisLabelTextColor = 'rgb(135,135,135)';

option = {

    backgroundColor: 'rgb(41,41,43)',

    title: {

        text: '中国GIS高校分布-2014年',

        x: 'center',

        y: 10,

        textStyle:{

            color:'#B4B4B4',

            fontSize:18,

            fontWeight:'normal',

        },

    },

    xAxis: {

        data: xData,

        axisLabel: {

            textStyle: {

                color: axisLabelTextColor

            },

            rotate: 45,

        },

    },

    yAxis: {

        name: "数量(所)",

        nameTextStyle: {

            color: axisLabelTextColor

        },

        splitLine: {

            show: false

        },

        axisTick: {

            show: false

        },

        axisLine: {

            show: true

        },

        axisLabel: {

            color: axisLabelTextColor

        }

    },

    series: [{

        name: '省份',

        type: 'pictorialBar',

        symbol: 'triangle',

        symbolPosition: 'start',

        itemStyle: {

            normal: {

                //opacity: 0.5

            },

            emphasis: {

                opacity: 1

            },

        },

        color: {

            type: 'linear',

            x: 0,

            y: 0,

            x2: 0,

            y2: 1,

            colorStops: [{

                offset: 1,

                color: 'rgb(78,9,72)' // 0% 处的颜色

            }, {

                offset: 0,

                color: 'rgb(255,0,0)' // 100% 处的颜色

            }],

        },

        data: cities,

        z: 10,

        markLine: {

            symbol: [0, 'none'],

            label: {

                normal: {

                    show: false

                }

            },

            lineStyle: {

                normal: {

                    color: 'rgb(80,80,80)',

                    width: 1

                },

                emphasis: {

                    width: 1,

                    type: 'dashed'

                },

            },

            data: lineData

        },

        markPoint: {

            symbol: 'circle',

            symbolSize: 0.1,

            data: pointData

        }

    }, {

        name: '数量',

        type: 'pictorialBar',

        symbolPosition: 'end',

        color: 'rgb(0,255,0)',

        //color:'rgba(156,107,211,0.5)',

        symbolOffset: [0, -10],

        data: vData

    }]

};

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

HappyPort

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

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

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

打赏作者

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

抵扣说明:

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

余额充值