vue echarts图表添加背景图

实现效果:

 代码实现:

var color = new echarts.graphic.LinearGradient(
    0, 0, 1, 0, // 这四个参数分别表示渐变的起点 (x1, y1) 与终点 (x2, y2) 的位置
    [
        {offset: 0, color: 'green'},   // 0% 处的颜色
        {offset: 0.5, color: 'blue'},   // 50% 处的颜色
        {offset: 1, color: 'orange'}   // 100% 处的颜色
    ]
);
option = {
   grid:{
            show:true,  
            backgroundColor:color,
        },
            title: {
                text: ''
            },
            tooltip: {},
            xAxis: {
                data: ["周一","周二","周三","周四","周五","周六"]
            },
            yAxis: {},
            series: [{
                name: '任务',
                type: 'bar',
                data: [5, 20, 36, 10, 10, 20]
            }]
};

如果需要整个图表都添加颜色的情况,不需要grid属性,直接在option下backgroundColor:color即可,如下图所示。

 

posted @ 2024-07-30 17:12  _houjie  阅读(478)  评论(0)    收藏  举报