Echarts的legend改变图例图标为自定义图片

1、自定义每个图例样式:为data的每个对象修改icon属性

legend:{
    show:true,
    orient:'horizontal',
    borderColor:'#df3434',
    borderWidth:2,
    data:[
        {
            name:'蒸发量',
            textStyle:{
                fontSize:12,
                fontWeight:'bolder',
                color:'#cccccc'
            },
            icon:'stack'
        },
        {
            name:'降水量',
            textStyle:{
                fontSize:12,
                fontWeight:'bolder',
                color:'#df3434'
            },
            icon:'pie'
        }
    ]
}

2、修改图例的图标为自定义图片

  首先我找了如下两张图片放在根目录下的images文件夹下

legend:{
    show:true,
    orient:'horizontal',
    borderColor:'#df3434',
    borderWidth:2,
    data:[
        {
            name:'蒸发量',
            textStyle:{
                fontSize:12,
                fontWeight:'bolder',
                color:'#cccccc'
            },
            icon:'image://./images/icon1.png'//格式为'image://+icon文件地址',其中image::后的//不能省略
        },
        {
            name:'降水量',
            textStyle:{
                fontSize:12,
                fontWeight:'bolder',
                icon:'image://./images/icon2.png'//格式为'image://+icon文件地址',其中image::后的//不能省略
            },
            icon:'pie'
        }
    ]
}

猜你喜欢

转载自www.cnblogs.com/goloving/p/9113830.html