echarts折线图 labelLine+symbol渐变

echarts折线图 labelLine+symbol渐变

效果图

在这里插入图片描述

实例代码

function gradientColor(startColor, endColor, step) {
    var startRGB = this.hexToRgb(startColor),
    startR = startRGB.r,
    startG = startRGB.g,
    startB = startRGB.b,
    endRGB = this.hexToRgb(endColor),
    endR = endRGB.r,
    endG = endRGB.g,
    endB = endRGB.b,
    sR = (endR - startR) / step,
    sG = (endG - startG) / step,
    sB = (endB - startB) / step;
    var colorArr = [];
    for (var i = 0; i < step; i++) {
        var hex = this.rgbToHex('rgb(' + parseInt((sR * i + startR)) + ',' + parseInt((sG * i + startG)) + ',' + parseInt((sB * i + startB)) + ')');
        colorArr.push(hex);
    }
    return colorArr;
}
gradientColor.prototype.hexToRgb = function(hex){
    return {
        r: parseInt("0x" + hex.slice(1, 3)),
        g: parseInt("0x" + hex.slice(3, 5)),
        b: parseInt("0x" + hex.slice(5, 7)),
        rgb: "rgba(" + parseInt("0x" + hex.slice(1, 3)) + "," + parseInt("0x" + hex.slice(3, 5)) + "," + parseInt("0x" + hex.slice(5, 7)) + ")"
    };
}
gradientColor.prototype.rgbToHex = function(color){
    var rgb = color.split(',')
    var r = parseInt(rgb[0].split('(')[1])
    var g = parseInt(rgb[1])
    var b = parseInt(rgb[2].split(')')[0])
    var hex = "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
    return hex
}
var sdata = [820, 932, 901, 934, 1290, 1330,1320];
var colors = new gradientColor('#0987F6','#04BBFD',7);
sdata = sdata.map((item,idx) => {
    return {
        value: item,
        itemStyle: {
            borderColor: colors[idx]
        }
    }
})
option = {
    backgroundColor: '#122A42',
    xAxis: {
        type: 'category',
        axisTick: {
            show:false,
        },
        axisLabel: {
            color: '#fff'
        },
        axisLine: {
            lineStyle: {
                color: '#314963'
            }
        },
        data: ['7.24', '7.25', '7.26', '7.27', '7.28', '7.29', '7.30']
    },
    yAxis: {
        type: 'value',
        axisTick: {
            show:false,
        },
        axisLabel: {
            color: '#fff'
        },
        axisLine: {
            lineStyle: {
                color: '#314963'
            }
        },
        splitLine: {
            show:false
        },
        min:function(value){
            return parseInt((value.min - (value.max - value.min)/4) || 0);
        },
        max:function(value){
            return parseInt((value.max + (value.max - value.min)/4) || 0);
        },
        interval: 200
    },
    series: [{
        data: sdata,
        type: 'line',
        symbolSize: 10,
        hoverAnimation: false,
        label: {
            show:true,
            color: '#fff',
            fontSize: 14,
            textShadowColor: '#000',
            textShadowBlur: 5,
            
        },
        lineStyle: {
            width: 5, 
            type: 'solid', 
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ 
                offset: 0, 
                color: '#04BBFD' 
            }, { 
                offset: 1, 
                color: '#0987F6' 
            }]),
            shadowColor: 'rgba(0,0,0,1)',
            shadowBlur: 10,
        },
        itemStyle: {
            borderWidth: 10,
        }
    }]
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值