echarts折线图中图例渐变+折线渐变+折线下方区域渐变+提示框中图标渐变

4,287 阅读1分钟

一、设计图

image.png

二、echarts中的渐变

image.png

渐变色或纹理填充

// 线性渐变,前四个参数分别是 x0, y0, x2, y2, 范围从 0 - 1,相当于在图形包围盒中的百分比,如果 globalCoord  `true`,则该四个值是绝对的像素位置 
{ 
    type: 'linear',
    x: 0,
    y: 0,
    x2: 0,
    y2: 1,
    colorStops: [
    { 
        offset: 0, color: 'red' // 0% 处的颜色 
    },
    { 
        offset: 1, color: 'blue' // 100% 处的颜色 
    }
 ], 
    global: false // 缺省为 false 
}
// 径向渐变,前三个参数分别是圆心 x, y 和半径,取值同线性渐变 
{ 
    type: 'radial', 
    x: 0.5, 
    y: 0.5, 
    r: 0.5, 
    colorStops: [{ 
        offset: 0, 
        color: 'red' // 0% 处的颜色 
    }, { 
        offset: 1, 
        color: 'blue' // 100% 处的颜色 
    }], 
        global: false // 缺省为 false 
}
// 纹理填充 
{ 
    image: imageDom, // 支持为 HTMLImageElement, HTMLCanvasElement,不支持路径字符串 
    repeat: 'repeat' // 是否平铺,可以是 'repeat-x', 'repeat-y', 'no-repeat' 
}

三、渐变案例实现

1.折线渐变

series的itemStyle中

image.png

2.下方区域渐变

series的areaStyle中

image.png

3.图例渐变

image.png

image.png

4.提示框中圆点渐变

image.png

image.png

输出formatter中的param:

image.png

发现我们提示框中需要的数据,在这里都有。而小圆点则是marker,我们根据个人需求修改其中html的内容:

image.png

并将自己需要的其他文字内容按格式拼接,完成。